diff --git a/pgweb/mailqueue/util.py b/pgweb/mailqueue/util.py index cd5e3eec..e2f3f7c6 100644 --- a/pgweb/mailqueue/util.py +++ b/pgweb/mailqueue/util.py @@ -15,7 +15,7 @@ def _encoded_email_header(name, email): return email -def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, usergenerated=False, cc=None, replyto=None, sendername=None, receivername=None, messageid=None): +def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, usergenerated=False, cc=None, replyto=None, sendername=None, receivername=None, messageid=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 @@ -33,6 +33,16 @@ def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, userge msg['Message-ID'] = messageid else: msg['Message-ID'] = make_msgid() + 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' + + # Is this email auto-generated or auto-replied? + if is_auto_reply: + msg['Auto-Submitted'] = 'auto-replied' + elif not usergenerated: + msg['Auto-Submitted'] = 'auto-generated' msg.attach(MIMEText(msgtxt, _charset='utf-8')) diff --git a/pgweb/util/admin.py b/pgweb/util/admin.py index f86a692d..9e02eddb 100644 --- a/pgweb/util/admin.py +++ b/pgweb/util/admin.py @@ -78,7 +78,8 @@ class PgwebAdmin(admin.ModelAdmin): send_simple_mail(settings.NOTIFICATION_FROM, obj.org.email, "postgresql.org moderation notification", - msgstr) + msgstr, + suppress_auto_replies=False) # Also generate a mail to the moderators send_simple_mail( diff --git a/pgweb/util/misc.py b/pgweb/util/misc.py index 5d45b7a0..2698031e 100644 --- a/pgweb/util/misc.py +++ b/pgweb/util/misc.py @@ -9,16 +9,20 @@ from pgweb.util.helpers import template_to_string import re -def send_template_mail(sender, receiver, subject, templatename, templateattr={}, usergenerated=False, cc=None, replyto=None, receivername=None, sendername=None, messageid=None): +def send_template_mail(sender, receiver, subject, templatename, templateattr={}, usergenerated=False, cc=None, replyto=None, receivername=None, sendername=None, messageid=None, suppress_auto_replies=True, is_auto_reply=False): d = { 'link_root': settings.SITE_ROOT, } d.update(templateattr) - send_simple_mail(sender, receiver, subject, - template_to_string(templatename, d), - usergenerated=usergenerated, cc=cc, replyto=replyto, - receivername=receivername, sendername=sendername, - messageid=messageid) + send_simple_mail( + sender, receiver, subject, + template_to_string(templatename, d), + usergenerated=usergenerated, cc=cc, replyto=replyto, + receivername=receivername, sendername=sendername, + messageid=messageid, + suppress_auto_replies=suppress_auto_replies, + is_auto_reply=is_auto_reply, + ) def get_client_ip(request):