@@ -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 \n Note: 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