diff --git a/app/email_utils.py b/app/email_utils.py index 8e7b6cf0..e3d0671e 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -1399,12 +1399,15 @@ def parse_full_address(full_address) -> (str, str): return full_address.display_name, full_address.address -def save_email_for_debugging(msg: Message) -> str: +def save_email_for_debugging(msg: Message, file_name_prefix=None) -> str: """Save email for debugging to temporary location Return the file path """ if TEMP_DIR: file_name = str(uuid.uuid4()) + ".eml" + if file_name_prefix: + file_name = file_name_prefix + file_name + with open(os.path.join(TEMP_DIR, file_name), "wb") as f: f.write(msg.as_bytes()) diff --git a/email_handler.py b/email_handler.py index 50d66d9c..fccc0476 100644 --- a/email_handler.py +++ b/email_handler.py @@ -2375,13 +2375,16 @@ class MailHandler: return status.E524 except Exception as e: LOG.e( - "email handling fail with error:%s mail_from:%s, rcpt_tos:%s, header_from:%s, header_to:%s, saved to %s", + "email handling fail with error:%s " + "mail_from:%s, rcpt_tos:%s, header_from:%s, header_to:%s, saved to %s", e, envelope.mail_from, envelope.rcpt_tos, msg[headers.FROM], msg[headers.TO], - save_email_for_debugging(msg), # todo: remove + save_email_for_debugging( + msg, file_name_prefix=e.__class__.__name__ + ), # todo: remove ) return status.E404