Fix up email error handling a little bit (needs lots more work)
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 20 Mar 2013 18:07:58 +0100
changeset 36 aad604d5dd52
parent 35 7fdde44ee633
child 37 a1e8a529aa46
push id31
push userbsmedberg@mozilla.com
push date2013-03-20 17:08 +0000
Fix up email error handling a little bit (needs lots more work)
weeklyupdates/mail.py
--- a/weeklyupdates/mail.py
+++ b/weeklyupdates/mail.py
@@ -29,24 +29,23 @@ def sendmails(messages, fromaddress=None
         if recipientlist is not None:
             messageto = recipientlist
         else:
             messageto = [message['To']]
 
         try:
             session.sendmail(messagefrom, messageto, message.as_string())
         except AttributeError, e:
-            print e
-            try:
-                print "Exception sending mail from %r to %r" % (fromaddress, recipientlist)
-            except:
-                pass
-        except smtplib.SMTPException:
-            pass
-    session.quit()
+            cherrypy.log.error("Exception sending mail from %r to %r: %s" % (fromaddress, recipientlist, e))
+        except smtplib.SMTPException, e:
+            cherrypy.log.error("Exception sending mail from %r to %r: %s" % (fromaddress, recipientlist, e))
+    try:
+        session.quit()
+    except smtplib.SMTPException:
+        pass
 
 def sendpost(fromaddress, tolist, recipientlist, post):
     subject = "Status Update: %s on %s" % (post.username, post.postdate.isoformat())
 
     message = email.mime.multipart.MIMEMultipart('alternative')
     message['To'] = ', '.join(tolist)
     message['From'] = fromaddress
     message['Sender'] = 'weekly-updates@smedbergs.us'