aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-03-21 10:30:23 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-03-21 10:30:23 +0100
commitecb73e376e4807087a87d38f73d7699b69c241f1 (patch)
tree7296e11652c64232d175a9a07da0f7919d598a67
parentmsg.as_string enode the content in base64 (diff)
downloadnewspipe-ecb73e376e4807087a87d38f73d7699b69c241f1.tar.gz
newspipe-ecb73e376e4807087a87d38f73d7699b69c241f1.tar.bz2
newspipe-ecb73e376e4807087a87d38f73d7699b69c241f1.zip
fixed email encoding issue
-rw-r--r--newspipe/notifications/emails.py11
-rw-r--r--newspipe/notifications/notifications.py8
2 files changed, 9 insertions, 10 deletions
diff --git a/newspipe/notifications/emails.py b/newspipe/notifications/emails.py
index 296e793d..44b1d8b3 100644
--- a/newspipe/notifications/emails.py
+++ b/newspipe/notifications/emails.py
@@ -23,6 +23,7 @@ import logging
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
+from email import charset
from newspipe.bootstrap import application
from newspipe.web.decorators import async_maker
@@ -41,7 +42,7 @@ def send_async_email(mfrom, mto, msg):
except Exception:
logger.exception("send_async_email raised:")
else:
- s.sendmail(mfrom, mto, msg.as_string())
+ s.sendmail(mfrom, mto, msg.as_bytes().decode(encoding="UTF-8"))
s.quit()
@@ -58,19 +59,21 @@ def send_smtp(to="", subject="", plaintext="", html=""):
"""
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart("alternative")
+ ch = charset.add_charset("utf-8", charset.QP)
+ msg.set_charset(ch)
msg["Subject"] = subject
msg["From"] = application.config["MAIL_DEFAULT_SENDER"]
msg["To"] = to
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(plaintext, "plain", "utf-8")
- part2 = MIMEText(html, "html", "utf-8")
+ # part2 = MIMEText(html, "html", "utf-8")
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
- msg.attach(part2)
+ # msg.attach(part2)
try:
s = smtplib.SMTP(application.config["MAIL_SERVER"])
@@ -85,6 +88,6 @@ def send_smtp(to="", subject="", plaintext="", html=""):
s.sendmail(
application.config["MAIL_DEFAULT_SENDER"],
msg["To"],
- msg.as_bytes().decode(encoding='UTF-8'),
+ msg.as_bytes().decode(encoding="UTF-8"),
)
s.quit()
diff --git a/newspipe/notifications/notifications.py b/newspipe/notifications/notifications.py
index 633af4c3..debbee61 100644
--- a/newspipe/notifications/notifications.py
+++ b/newspipe/notifications/notifications.py
@@ -46,9 +46,7 @@ def new_account_notification(user, email):
)
emails.send(
- to=email,
- subject="[Newspipe] Account creation",
- plaintext=plaintext,
+ to=email, subject="[Newspipe] Account creation", plaintext=plaintext,
)
@@ -58,7 +56,5 @@ def new_password_notification(user, password):
"""
plaintext = render_template("emails/new_password.txt", user=user, password=password)
emails.send(
- to=user.email,
- subject="[Newspipe] New password",
- plaintext=plaintext,
+ to=user.email, subject="[Newspipe] New password", plaintext=plaintext,
)
bgstack15