Set proper mail headers to indicate auto-generated mails
authorMagnus Hagander <magnus@hagander.net>
Sun, 17 Jan 2021 15:08:00 +0000 (16:08 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sun, 17 Jan 2021 15:08:00 +0000 (16:08 +0100)
hamnadmin/hamnadmin/mailqueue/util.py

index 1e39dd81fc24a62870270c384e1962b5e740afc0..1bdca7fc08744c6b596ecb709529508abd800bce 100644 (file)
@@ -14,7 +14,7 @@ def _encoded_email_header(name, email):
     return email
 
 
-def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, bcc=None, sendername=None, receivername=None):
+def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, bcc=None, sendername=None, receivername=None, suppress_auto_replies=True):
     # attachment format, each is a tuple of (name, mimetype,contents)
     # content should be *binary* and not base64 encoded, since we need to
     # use the base64 routines from the email library to get a properly
@@ -25,6 +25,10 @@ def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, bcc=No
     msg['From'] = _encoded_email_header(sendername, sender)
     msg['Date'] = formatdate(localtime=True)
 
+    if suppress_auto_replies:
+        msg['X-Auto-Response-Suppress'] = 'All'
+        msg['Auto-Submitted'] = 'auto-generated'
+
     msg.attach(MIMEText(msgtxt, _charset='utf-8'))
 
     if attachments: