Commits

Anonymous committed ef3e821

fail silently option

Comments (0)

Files changed (2)

flaskext/mail/__init__.py

         self.use_ssl = app.config.get('MAIL_USE_SSL', False)
         self.debug = int(app.config.get('MAIL_DEBUG', app.debug))
         self.max_emails = app.config.get('DEFAULT_MAX_EMAILS')
+        self.fail_silently = app.config.get('MAIL_FAIL_SILENTLY', True)
+
         self.testing = app.testing
         
         self.app = app

flaskext/mail/connection.py

 import smtplib
+import socket
 
 from flaskext.mail.message import Message
 from flaskext.mail.signals import email_dispatched
         self.app = self.mail.app
         self.testing = self.app.testing
         self.max_emails = max_emails or self.mail.max_emails or 0
+        self.fail_silently = self.mail.fail_silently
 
     def __enter__(self):
 
     
     def configure_host(self):
         
-        if self.mail.use_ssl:
-            host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
-        else:
-            host = smtplib.SMTP(self.mail.server, self.mail.port)
+        try:
+            if self.mail.use_ssl:
+                host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
+            else:
+                host = smtplib.SMTP(self.mail.server, self.mail.port)
+        except socket.error:
+            if not self.fail_silently:
+                raise
 
         host.set_debuglevel(int(self.app.debug))