aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-08-13 11:22:36 -0500
committerFrederick Muriuki Muriithi2024-08-13 11:52:14 -0500
commit12edc160df0ead9ac1ae4e62a44d49582e063021 (patch)
treee025d389f4771746d2f6cd5580ddf04bd005b648 /gn_auth
parent04501fdda362a71a7ba7c8abc1ee07d360b320ee (diff)
downloadgn-auth-12edc160df0ead9ac1ae4e62a44d49582e063021.tar.gz
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.
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/auth/authorisation/users/views.py1
-rw-r--r--gn_auth/settings.py1
-rw-r--r--gn_auth/smtp.py8
3 files changed, 6 insertions, 4 deletions
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)