Browse Source

fix DKIM fail on reply phase: the DKIM-signature should be added at the end of processing

Son NK 5 years ago
parent
commit
569fda47a9
1 changed files with 9 additions and 4 deletions
  1. 9 4
      email_handler.py

+ 9 - 4
email_handler.py

@@ -234,10 +234,10 @@ class MailHandler:
 
             return "250 ignored"
 
-        # todo: add DKIM-Signature for custom domain
-        # add DKIM-Signature for non-custom-domain alias
-        if alias.endswith(EMAIL_DOMAIN):
-            add_dkim_signature(msg, EMAIL_DOMAIN)
+        # remove DKIM-Signature
+        if msg["DKIM-Signature"]:
+            LOG.d("Remove DKIM-Signature %s", msg["DKIM-Signature"])
+            del msg["DKIM-Signature"]
 
         # email seems to come from alias
         msg.replace_header("From", alias)
@@ -258,6 +258,11 @@ class MailHandler:
             envelope.rcpt_options,
         )
 
+        # todo: add DKIM-Signature for custom domain
+        # add DKIM-Signature for non-custom-domain alias
+        if alias.endswith(EMAIL_DOMAIN):
+            add_dkim_signature(msg, EMAIL_DOMAIN)
+
         msg_raw = msg.as_string().encode()
         smtp.sendmail(
             alias,