not create html in send_email if html isn't set

This commit is contained in:
Son 2021-11-04 14:27:33 +01:00
parent 80bbfb6f4b
commit f8b6b20dd8
1 changed files with 7 additions and 7 deletions

View File

@ -268,13 +268,13 @@ def send_email(
else: else:
smtp = SMTP(POSTFIX_SERVER, POSTFIX_PORT or 25) smtp = SMTP(POSTFIX_SERVER, POSTFIX_PORT or 25)
msg = MIMEMultipart("alternative") if html:
msg.attach(MIMEText(plaintext)) msg = MIMEMultipart("alternative")
msg.attach(MIMEText(plaintext))
if not html: msg.attach(MIMEText(html, "html"))
LOG.d("Use plaintext as html") else:
html = plaintext.replace("\n", "<br>") msg = Message()
msg.attach(MIMEText(html, "html")) msg.set_payload(plaintext)
msg[headers.SUBJECT] = subject msg[headers.SUBJECT] = subject
msg[headers.FROM] = f"{SUPPORT_NAME} <{SUPPORT_EMAIL}>" msg[headers.FROM] = f"{SUPPORT_NAME} <{SUPPORT_EMAIL}>"