]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/utils/mail.py
adding a setting that allows the users to choose the comments order
[osqa.git] / forum / utils / mail.py
index 5f93b055338931dcd30f8f0b5bb4f76d128e6e12..84a79b35a876297fd0e0e9c5bff6ac605074378c 100644 (file)
@@ -59,8 +59,8 @@ def create_and_send_mail_messages(messages):
             sender = str(settings.DEFAULT_FROM_EMAIL)
 
         for recipient, subject, html, text, media in messages:
-           if connection is None:
-               connection = create_connection()
+            if connection is None:
+                connection = create_connection()
 
             msgRoot = MIMEMultipart('related')
 
@@ -88,18 +88,21 @@ def create_and_send_mail_messages(messages):
 
             try:
                 connection.sendmail(sender, [recipient.email], msgRoot.as_string())
-           except SMTPRecipientsRefused, e:
-               logging.error("Email address not accepted.  Exception: %s" % e)
+            except SMTPRecipientsRefused, e:
+                logging.error("Email address not accepted.  Exception: %s" % e)
             except Exception, e:
                 logging.error("Couldn't send mail using the sendmail method: %s" % e)
-               try:
-                   connection.quit()
-                   connection = None
-               except Exception:
-                   connection = None
+                try:
+                    connection.quit()
+                except Exception, e:
+                    logging.error(e)
+                finally:
+                    connection = None
 
         try:
             connection.quit()
+        except AttributeError:
+            pass
         except socket.sslerror:
             connection.close()
     except Exception, e: