summaryrefslogtreecommitdiff
path: root/postgresqleu/mailqueue/util.py
diff options
context:
space:
mode:
authorMagnus Hagander2020-03-25 15:06:45 +0000
committerMagnus Hagander2020-03-25 15:07:43 +0000
commit2dace87abba3ff113513d9c7ad1aa15e7bac8eee (patch)
treeb636adedad85454a003303301420c8033e28a40f /postgresqleu/mailqueue/util.py
parentfb7bfb7097efacdc436a4be73b65426e921c5150 (diff)
Set flags indicating our outbound emails are auto-submitted
Since all of our emails are, set it for all emails for now, but keep flags around to make it possible to change in the future. Hoepfully these headers will help decrease then number of out-of-office emails received when sending things out.
Diffstat (limited to 'postgresqleu/mailqueue/util.py')
-rw-r--r--postgresqleu/mailqueue/util.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/postgresqleu/mailqueue/util.py b/postgresqleu/mailqueue/util.py
index 70543ebf..6693c51a 100644
--- a/postgresqleu/mailqueue/util.py
+++ b/postgresqleu/mailqueue/util.py
@@ -19,10 +19,11 @@ def template_to_string(templatename, attrs={}):
return get_template(templatename).render(context)
-def send_template_mail(sender, receiver, subject, templatename, templateattr={}, attachments=None, bcc=None, sendername=None, receivername=None):
+def send_template_mail(sender, receiver, subject, templatename, templateattr={}, attachments=None, bcc=None, sendername=None, receivername=None, suppress_auto_replies=True, is_auto_reply=False):
send_simple_mail(sender, receiver, subject,
template_to_string(templatename, templateattr),
- attachments, bcc, sendername, receivername)
+ attachments, bcc, sendername, receivername,
+ suppress_auto_replies, is_auto_reply)
def _encoded_email_header(name, email):
@@ -31,7 +32,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, is_auto_reply=False):
# 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
@@ -41,6 +42,14 @@ def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, bcc=No
msg['To'] = _encoded_email_header(receivername, receiver)
msg['From'] = _encoded_email_header(sendername, sender)
msg['Date'] = formatdate(localtime=True)
+ if suppress_auto_replies:
+ # Do our best to set some headers to indicate that auto-replies like out of office
+ # messages should not be sent to this email.
+ msg['X-Auto-Response-Suppress'] = 'All'
+ if is_auto_reply:
+ msg['Auto-Submitted'] = 'auto-replied'
+ else:
+ msg['Auto-Submitted'] = 'auto-generated'
msg.attach(MIMEText(msgtxt, _charset='utf-8'))