Skip to content

Commit

Permalink
Merge pull request #995 from simple-login/allow-change-from
Browse files Browse the repository at this point in the history
Allow to use a different from for send_email()
  • Loading branch information
acasajus authored May 16, 2022
2 parents 4a4d4a5 + 41c6e8f commit a224f4f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/email_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a224f4f

Please sign in to comment.