Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reply-To header #5

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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