Skip to content

Commit 2f6d19a

Browse files
committed
feat: handle subject and reply-to
1 parent 8c787e5 commit 2f6d19a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

hook2mail.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def webhook():
2828

2929
# Extract the original sender
3030
original_sender = email_message.get('From', 'Unknown Sender')
31+
original_subject = email_message.get('Subject', 'No Subject')
3132

3233
payload = None
3334
if email_message.is_multipart():
@@ -45,19 +46,21 @@ def webhook():
4546
if len(message_content) < 10:
4647
raise ValueError("The email body must have at least 10 characters")
4748

48-
send_email(message_content, original_sender)
49+
send_email(message_content, original_sender, original_subject)
4950
return "OK", 200
5051
except (KeyError, ValueError, base64.binascii.Error) as e:
5152
return jsonify({"error": str(e)}), 400
5253
except Exception as e:
5354
return jsonify({"error": str(e)}), 500
5455

55-
def send_email(content, original_sender):
56+
def send_email(content, original_sender, original_subject):
5657
msg = EmailMessage()
57-
msg.set_content(content)
58-
msg["Subject"] = f"Forwarded email from {original_sender}"
58+
forward_infos = f"\n\nNote: this message has been forwarded via hook2mail from {original_sender}"
59+
msg.set_content(content + forward_infos)
60+
msg["Subject"] = original_subject
5961
msg["From"] = EMAIL_FROM
6062
msg["To"] = EMAIL_TO
63+
msg.add_header('Reply-To', f"{original_sender}, {EMAIL_FROM}")
6164

6265
with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as server:
6366
if USE_STARTTLS:

0 commit comments

Comments
 (0)