[PATCH] Catch smtp exceptions
Christian Ebert
blacktrash at gmx.net
Fri Sep 7 09:50:25 CDT 2007
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1189176522 -7200
# Node ID 65b3553e7b8bd3705a3e96446a0491d11e8511dc
# Parent 18091102a6333d38c68fd6e590e6bfea0970b771
Catch smtp exceptions
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -411,7 +411,8 @@ def patchbomb(ui, repo, *revs, **opts):
ui.status('Sending ', m['Subject'], ' ...\n')
# Exim does not remove the Bcc field
del m['Bcc']
- mailer.sendmail(sender, to + bcc + cc, m.as_string(0))
+ mail.sendmail(ui, sender, to + bcc + cc, m.as_string(0),
+ mailer=mailer)
cmdtable = {
"email":
diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -66,8 +66,15 @@ def connect(ui):
return _sendmail(ui, method)
-def sendmail(ui, sender, recipients, msg):
- return connect(ui).sendmail(sender, recipients, msg)
+def sendmail(ui, sender, recipients, msg, mailer=None):
+ m = mailer or connect(ui)
+ try:
+ return m.sendmail(sender, recipients, msg)
+ except smtplib.SMTPRecipientsRefused, inst:
+ recipients = [r[1] for r in inst.recipients.values()]
+ raise util.Abort('\n' + '\n'.join(recipients))
+ except smtplib.SMTPException, inst:
+ raise util.Abort(inst)
def validateconfig(ui):
'''determine if we have enough config data to try sending email.'''
More information about the Mercurial-devel
mailing list