From 695a628e689648802b120e290918e9866755849e Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Wed, 15 Sep 2021 09:28:54 +0200 Subject: [PATCH] save email that can't be DKIM signed to temp dir to investigate --- app/email_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/email_utils.py b/app/email_utils.py index 9b3140cf..ac219f6b 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -6,6 +6,7 @@ import quopri import random import re import time +import uuid from copy import deepcopy from email.header import decode_header, Header from email.message import Message @@ -45,6 +46,7 @@ from app.config import ( TRANSACTIONAL_BOUNCE_EMAIL, ALERT_SPF, POSTFIX_PORT_FORWARD, + TEMP_DIR, ) from app.dns_utils import get_mx_domains from app.extensions import db @@ -409,6 +411,14 @@ def add_dkim_signature(msg: Message, email_domain: str): # try with another headers continue + # To investigate why some emails can't be DKIM signed. todo: remove + if TEMP_DIR: + file_name = str(uuid.uuid4()) + ".eml" + with open(os.path.join(TEMP_DIR, file_name), "wb") as f: + f.write(msg.as_bytes()) + + LOG.w("email saved to %s", file_name) + raise Exception("Cannot create DKIM signature")