mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
digest: log send failures and unsubscribe hard-bounce emails.
(imported from commit 3ffcc335d4d3ad3955da8981ff1129888fe681a4)
This commit is contained in:
@@ -286,6 +286,11 @@ def clear_followup_emails_queue(email, mail_client=None):
|
|||||||
print result.get("name"), result.get("error")
|
print result.get("name"), result.get("error")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def log_digest_event(msg):
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(filename=settings.DIGEST_LOG_PATH, level=logging.INFO)
|
||||||
|
logging.info(msg)
|
||||||
|
|
||||||
@uses_mandrill
|
@uses_mandrill
|
||||||
def send_future_email(recipients, email_html, email_text, subject,
|
def send_future_email(recipients, email_html, email_text, subject,
|
||||||
delay=datetime.timedelta(0), sender=None,
|
delay=datetime.timedelta(0), sender=None,
|
||||||
@@ -350,8 +355,27 @@ def send_future_email(recipients, email_html, email_text, subject,
|
|||||||
send_time = (datetime.datetime.utcnow() + delay).__format__("%Y-%m-%d %H:%M:%S")
|
send_time = (datetime.datetime.utcnow() + delay).__format__("%Y-%m-%d %H:%M:%S")
|
||||||
results = mail_client.messages.send(message=message, async=False, ip_pool="Main Pool", send_at=send_time)
|
results = mail_client.messages.send(message=message, async=False, ip_pool="Main Pool", send_at=send_time)
|
||||||
problems = [result for result in results if (result['status'] in ('rejected', 'invalid'))]
|
problems = [result for result in results if (result['status'] in ('rejected', 'invalid'))]
|
||||||
|
|
||||||
if problems:
|
if problems:
|
||||||
raise Exception("While sending email (%s), encountered problems with these recipients: %r"
|
for problem in problems:
|
||||||
|
if problem["status"] == "rejected":
|
||||||
|
if problem["reject_reason"] == "hard-bounce":
|
||||||
|
# A hard bounce means the address doesn't exist or the
|
||||||
|
# recipient mail server is completely blocking
|
||||||
|
# delivery. Don't try to send further emails.
|
||||||
|
if "digest-emails" in tags:
|
||||||
|
from zerver.lib.actions import do_change_enable_digest_emails
|
||||||
|
bounce_email = problem["email"]
|
||||||
|
user_profile = get_user_profile_by_email(bounce_email)
|
||||||
|
do_change_enable_digest_emails(user_profile, False)
|
||||||
|
log_digest_event("%s\nTurned off digest emails for %s" % (
|
||||||
|
str(problems), bounce_email))
|
||||||
|
continue
|
||||||
|
elif problem["reject_reason"] == "soft-bounce":
|
||||||
|
# A soft bounce is temporary; let it try to resolve itself.
|
||||||
|
continue
|
||||||
|
raise Exception(
|
||||||
|
"While sending email (%s), encountered problems with these recipients: %r"
|
||||||
% (subject, problems))
|
% (subject, problems))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user