Skip to content

Commit

Permalink
Merge pull request #5 from NatLibFi/ekir-202-reply-to
Browse files Browse the repository at this point in the history
Add Reply-To header
  • Loading branch information
natlibfi-max-grasbeck authored Jun 4, 2024
2 parents 32709f5 + 58cc1b7 commit 20cb522
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def feedback(name=None):
body += f"\n\nOhjelmistoversio: {version_name} ({version_code}) (commit: {commit})"
body += f"\n\nUser agent: {user_agent}"

sent = send_email(subject, body, recipients)
sent = send_email(subject, body, reply_to, recipients)

if sent:
return redirect(url_for("success"))
Expand Down Expand Up @@ -157,7 +157,20 @@ def feedback(name=None):
)


def send_email(subject, body, recipients):

def send_email(subject, body, reply_to, recipients):
'''Function that sends emails to recipients.
Args:
subject (str): the subject field of the email message to be sent
body (str): the text body of the email being sent
reply_to (str): The Reply-To header value
recipients (list): List of recipients
Returns:
bool: Return value is True if message was sent or False if not
'''

# Prevents duplicates
recipients = list(set(recipients))
message = EmailMessage()
Expand All @@ -166,6 +179,9 @@ def send_email(subject, body, recipients):
message["To"] = ",".join(recipients)
message["From"] = app.config["MAIL_SENDER"]
message["Subject"] = subject
# Setting the Reply-To header here so that replying to emails is more convenient
if reply_to:
message["Reply-To"] = reply_to

context = ssl.SSLContext(ssl.PROTOCOL_TLS)
server = app.config["MAIL_SERVER"]
Expand Down

0 comments on commit 20cb522

Please sign in to comment.