From e61bf038be5305f9bc98d967515f2d6f9ad7b0a5 Mon Sep 17 00:00:00 2001 From: Son Date: Mon, 16 May 2022 19:17:56 +0200 Subject: [PATCH 1/2] allow to use a different from for send_email() --- app/email_utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index 2c4664ed0..78079acd8 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -291,6 +291,8 @@ def send_email( unsubscribe_via_email=False, retries=0, # by default no retry if sending fails ignore_smtp_error=False, + from_name=None, + from_addr=None, ): to_email = sanitize_email(to_email) if NOT_SEND_EMAIL: @@ -305,6 +307,9 @@ def send_email( LOG.d("send email to %s, subject '%s'", to_email, subject) + from_name = from_name or NOREPLY + from_addr = from_addr or NOREPLY + if html: msg = MIMEMultipart("alternative") msg.attach(MIMEText(plaintext)) @@ -315,7 +320,7 @@ def send_email( msg[headers.CONTENT_TYPE] = "text/plain" msg[headers.SUBJECT] = subject - msg[headers.FROM] = f"{NOREPLY} <{NOREPLY}>" + msg[headers.FROM] = f"{from_name} <{from_addr}>" msg[headers.TO] = to_email msg_id_header = make_msgid(domain=EMAIL_DOMAIN) @@ -334,7 +339,7 @@ def send_email( ) # add DKIM - email_domain = NOREPLY[NOREPLY.find("@") + 1 :] + email_domain = from_addr[from_addr.find("@") + 1 :] add_dkim_signature(msg, email_domain) transaction = TransactionalEmail.create(email=to_email, commit=True) From 41c6e8fd79a2f26b7d7ed767499cb97cf18ea929 Mon Sep 17 00:00:00 2001 From: Son Date: Mon, 16 May 2022 19:23:24 +0200 Subject: [PATCH 2/2] add quote --- app/email_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/email_utils.py b/app/email_utils.py index 78079acd8..0c65df433 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -320,7 +320,7 @@ def send_email( msg[headers.CONTENT_TYPE] = "text/plain" msg[headers.SUBJECT] = subject - msg[headers.FROM] = f"{from_name} <{from_addr}>" + msg[headers.FROM] = f'"{from_name}" <{from_addr}>' msg[headers.TO] = to_email msg_id_header = make_msgid(domain=EMAIL_DOMAIN)