New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invitation email #1177
Invitation email #1177
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1177 +/- ##
==========================================
+ Coverage 80.21% 80.49% +0.27%
==========================================
Files 283 284 +1
Lines 24082 25195 +1113
==========================================
+ Hits 19318 20281 +963
- Misses 4764 4914 +150
Continue to review full report at Codecov.
|
07dd72e
to
d65f301
Compare
d65f301
to
29f85df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
54d7cd6
to
0b5b066
Compare
parsec/backend/invite.py
Outdated
@@ -173,21 +192,29 @@ async def send_invite_email( | |||
) | |||
|
|||
# Plain-text version used as backup if the html doesn't work for the client | |||
text = f"{line1}{parsec_url}\n{line2}\n{invite_link}\n{line4}" | |||
text = f"{body[0]}{parsec_url}\n{body[1]}\n{invite_link}\n{body[3]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems too fragile (for instance why do we skip body[2]
? ^^).
If we want to change the place invite_link is we have to change this part, the body list (for each language) and the html formating too... If we consider the body as a list of paragraph, we just have to move the {invite_link}
part in the body (well still for each language).
And the formatting becomes trivial:
body = MAIL_TEXT[lang]['body']
text_body = '\n'.join(body).format(sender_name=sender_name, parsec_url=parsec_url, invite_link=invite_link)
html_body = '<br>'.join(body).format(sender_name=sender_name, parsec_url=parsec_url, invite_link=invite_link)
html_template = importlib_resources.read_text(parsec.backend.mail, "invite_mail.tmpl.html")
html = html_template.format(body=html_body, preheader=MAIL_TEXT[lang]['preheader'], ...)
It seems you can add LANGUAGE headers to email messages RFC1766 §4.1 seems to present an example of multi-language message (https://tools.ietf.org/html/rfc1766):
see also https://tools.ietf.org/html/rfc2231.html Have you tried this kind of stuff in your email ? |
552c4bc
to
123616b
Compare
I've made a couple of tests for multilingual mails import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender_email = "no-reply@parsec.cloud"
# receiver_email = "yyy@gmail.com"
receiver_email = "xxx@gmail.com"
password = "xxxxxxxxxxxxx"
message = MIMEMultipart("alternative")
message["Subject"] = "Bonjour 2"
message["From"] = sender_email
message["To"] = receiver_email
# Create the plain-text and HTML version of your message
text_fr = """\
Salut,
Comment ça va ?
Real Python has many great tutorials:
www.realpython.com"""
html_fr = """\
<html>
<body>
<p>Salut,<br>
Comment ça va ?<br>
<a href="http://www.realpython.com">Real Python</a>
has many great tutorials.
</p>
</body>
</html>
"""
text_en = """\
Hi,
How are you?
Real Python has many great tutorials:
www.realpython.com"""
html_en = """\
<html>
<body>
<p>Hi,<br>
How are you?<br>
<a href="http://www.realpython.com">Real Python</a>
has many great tutorials.
</p>
</body>
</html>
"""
# Turn these into plain/html MIMEText objects
part_text_fr = MIMEText(text_fr, "plain")
part_html_fr = MIMEText(html_fr, "html")
part_text_en = MIMEText(text_en, "plain")
part_html_en = MIMEText(html_en, "html")
part_text_fr.add_header("Content-Language", "fr-FR")
part_html_fr.add_header("Content-Language", "fr-FR")
part_text_en.add_header("Content-Language", "en-US")
part_html_en.add_header("Content-Language", "en-US")
# Add HTML/plain-text parts to MIMEMultipart message
# The email client will try to render the last part first
message.attach(part_text_en)
message.attach(part_html_en)
message.attach(part_text_fr)
message.attach(part_html_fr)
# Create secure connection with server and send email
context = ssl.create_default_context()
with smtplib.SMTP("mail.gandi.net", 587) as server:
tls_ready = server.starttls(context=context)
if tls_ready[0] != 220:
print("TLS error:", tls_ready)
server.login(sender_email, password)
server.sendmail(
sender_email, receiver_email, message.as_string()
) which create this kind of email body:
However this doesn't seems to be handled correctly with mail clients (I've tried with gmail, the last html part is always used no matter it content-language type and the language of the gmail client) :'-( |
f87975b
to
7ad5a1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I've written quite a lot of comments to highlight the issues I'm facing, mostly :