aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/smtp.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn_auth/smtp.py')
-rw-r--r--gn_auth/smtp.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/gn_auth/smtp.py b/gn_auth/smtp.py
index 0c9f878..2f0e7f4 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", "genenetwork.org")
+ 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)
@@ -53,6 +53,9 @@ def send_message(# pylint: disable=[too-many-arguments]
"""Set up a connection to a SMTP server and send a message."""
logging.debug("Email to send:\n******\n%s\n******\n", message.as_string())
with smtplib.SMTP(host, port, local_hostname, timeout, source_address) as conn:
- conn.starttls()
- conn.login(smtp_user, smtp_passwd)
+ conn.ehlo()
+ if bool(smtp_user) and bool(smtp_passwd):
+ conn.starttls()
+ conn.login(smtp_user, smtp_passwd)
+
conn.send_message(message)