changeset 5472:23889160905a 0.9.5

Catch smtp exceptions
author Christian Ebert <blacktrash@gmx.net>
date Fri, 07 Sep 2007 16:48:42 +0200
parents 5b81c1cc6ebe
children 040984468440 800e2756c9ab
files hgext/patchbomb.py mercurial/mail.py
diffstat 2 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/patchbomb.py	Fri Oct 19 19:20:33 2007 +0000
+++ b/hgext/patchbomb.py	Fri Sep 07 16:48:42 2007 +0200
@@ -224,9 +224,8 @@
                 pass
             os.rmdir(tmpdir)
 
-    really_sending = not (opts['test'] or opts['mbox'])
-
-    if really_sending:
+    if not (opts['test'] or opts['mbox']):
+        # really sending
         mail.validateconfig(ui)
 
     if not (revs or opts.get('rev') or opts.get('outgoing')):
@@ -361,8 +360,6 @@
 
     ui.write('\n')
 
-    if really_sending:
-        mailer = mail.connect(ui)
     parent = None
 
     sender_addr = email.Utils.parseaddr(sender)[1]
@@ -411,7 +408,7 @@
             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))
 
 cmdtable = {
     "email":
--- a/mercurial/mail.py	Fri Oct 19 19:20:33 2007 +0000
+++ b/mercurial/mail.py	Fri Sep 07 16:48:42 2007 +0200
@@ -67,7 +67,13 @@
     return _sendmail(ui, method)
 
 def sendmail(ui, sender, recipients, msg):
-    return connect(ui).sendmail(sender, recipients, msg)
+    try:
+        return connect(ui).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.'''