Anonymous avatar 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))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.