From 12edc160df0ead9ac1ae4e62a44d49582e063021 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 13 Aug 2024 11:22:36 -0500 Subject: Emails: Make "From" address configurable We are running GeneNetwork in different environments. Each environment could have it's own separate domain, and need a different sender email to allow the underlying services to allow the emails through. --- gn_auth/auth/authorisation/users/views.py | 1 + gn_auth/settings.py | 1 + gn_auth/smtp.py | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'gn_auth') diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index eb1870f..363da92 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -154,6 +154,7 @@ def send_verification_email( send_message(smtp_user=current_app.config["SMTP_USER"], smtp_passwd=current_app.config["SMTP_PASSWORD"], message=build_email_message( + from_address=current_app.config["EMAIL_ADDRESS"], to_addresses=(user_address(user),), subject=subject, txtmessage=__render__("emails/verify-email.txt"), diff --git a/gn_auth/settings.py b/gn_auth/settings.py index 6015560..2a78be3 100644 --- a/gn_auth/settings.py +++ b/gn_auth/settings.py @@ -42,3 +42,4 @@ SMTP_PORT = 587 SMTP_TIMEOUT = 200 # seconds SMTP_USER = "no-reply@genenetwork.org" SMTP_PASSWORD = "asecrettoken" +EMAIL_ADDRESS = "no-reply@uthsc.edu" diff --git a/gn_auth/smtp.py b/gn_auth/smtp.py index a2d86b0..3306765 100644 --- a/gn_auth/smtp.py +++ b/gn_auth/smtp.py @@ -17,17 +17,17 @@ def __read_mime__(filepath) -> dict: def build_email_message(# pylint: disable=[too-many-arguments] + from_address: str, to_addresses: tuple[Address, ...], subject: str, txtmessage: str, htmlmessage: str = "", - attachments: tuple[str, ...] = tuple(), - from_address: Address = Address( - "GeneNetwork Automated Emails", "no-reply", "uthsc.edu") + attachments: tuple[str, ...] = tuple() ) -> EmailMessage: """Build an email message.""" msg = EmailMessage() - msg["From"] = from_address + msg["From"] = Address(display_name="GeneNetwork Automated Emails", + addr_spec=from_address) msg["To"] = to_addresses msg["Subject"] = subject msg.set_content(txtmessage) -- cgit v1.2.3