From 718854a82254aecec1d20e3df387129925afe504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= Date: Wed, 17 Jan 2024 23:25:49 +0000 Subject: [PATCH] chore: better failed message structure --- src/netius/extra/smtp_r.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/netius/extra/smtp_r.py b/src/netius/extra/smtp_r.py index 595c50ec..52e6138f 100644 --- a/src/netius/extra/smtp_r.py +++ b/src/netius/extra/smtp_r.py @@ -208,13 +208,15 @@ def relay_postmaster(self, reply_to, context, exception): # builds the contents of the message, using the extracted # exception information tos_s = ",".join(context.get("tos", [])) - subject = "Problem sending SMTP email to: %s" % tos_s - contents = "Subject: %s\r\n\r\n%s\r\n%s\r\nDetails: %s" % ( - subject, - subject, - message, - "\n".join(details) or "-" - ) + contents_o = context.get("contents", []) + subject = "Delivery Status Notification (Failure) - %s" % tos_s + contents_l = [] + contents_l.append("Subject: %s\r\n\r\n" % subject) + contents_l.append("%s\r\n" % subject) + contents_l.append("Message: %s\r\n" % message) + contents_l.append("Details: %s\r\n\r\n" % ("\n".join(details) or "-")) + contents_l.append("----- Original message -----\r\n\r\n%s" % contents_o) + contents = "".join(contents_l) # builds a new SMTP client that is going to be used # for the postmaster operation, ensures that the