Fixes email sending.

Now works with HTML + alternative plain text + attachments.
This commit is contained in:
Alexis M 2019-09-30 17:59:39 +02:00
parent cfd9543d92
commit 1cbdc56969

View file

@ -13,10 +13,7 @@ def send(to, subject, body, html=None, copy=None, attachments=None):
if not attachments: if not attachments:
attachments = [] attachments = []
msg = MIMEMultipart() msg = MIMEMultipart('alternative')
msg.attach(MIMEText(body, "plain"))
if html:
msg.attach(MIMEText(html, "html"))
msg["Subject"] = subject msg["Subject"] = subject
msg["From"] = config.FROM_EMAIL msg["From"] = config.FROM_EMAIL
msg["To"] = to msg["To"] = to
@ -30,6 +27,11 @@ def send(to, subject, body, html=None, copy=None, attachments=None):
filename=file_name) filename=file_name)
encoders.encode_base64(part) encoders.encode_base64(part)
msg.attach(part) msg.attach(part)
msg.attach(MIMEText(body, "plain"))
if html:
msg.attach(MIMEText(html, "html"))
if not config.SEND_EMAILS: if not config.SEND_EMAILS:
return print("Sending email", str(body)) return print("Sending email", str(body))
try: try: