Commits

Andriy Kornatskyy committed e06110b

Terminate SMTP session in case sendmail error.

Comments (0)

Files changed (1)

src/wheezy/core/mail.py

         content = ntob(mime(message).as_string(), message.charset)
         # keep connection scope minimal
         client = self.connect()
-        client.sendmail(message.from_addr, recepients, content)
-        client.quit()
+        try:
+            client.sendmail(message.from_addr, recepients, content)
+        finally:
+            client.quit()
 
     def send_multi(self, messages):
         """ Sends multiple mail messages.
                 for message in messages]
         # keep connection scope minimal
         client = self.connect()
-        for arg in args:
-            client.sendmail(*arg)
-        client.quit()
+        try:
+            for arg in args:
+                client.sendmail(*arg)
+        finally:
+            client.quit()
 
     def connect(self):
         smtp = SMTP()