Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MAIL_TIMEOUT #140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions flask_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ def __exit__(self, exc_type, exc_value, tb):

def configure_host(self):
if self.mail.use_ssl:
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port,
timeout=self.mail.timeout)
else:
host = smtplib.SMTP(self.mail.server, self.mail.port)
host = smtplib.SMTP(self.mail.server, self.mail.port,
timeout=self.mail.timeout)

host.set_debuglevel(int(self.mail.debug))

Expand Down Expand Up @@ -528,7 +530,8 @@ def connect(self):
class _Mail(_MailMixin):
def __init__(self, server, username, password, port, use_tls, use_ssl,
default_sender, debug, max_emails, suppress,
ascii_attachments=False):
ascii_attachments=False,
timeout=smtplib.socket._GLOBAL_DEFAULT_TIMEOUT):
self.server = server
self.username = username
self.password = password
Expand All @@ -540,6 +543,7 @@ def __init__(self, server, username, password, port, use_tls, use_ssl,
self.max_emails = max_emails
self.suppress = suppress
self.ascii_attachments = ascii_attachments
self.timeout = timeout


class Mail(_MailMixin):
Expand Down Expand Up @@ -567,7 +571,8 @@ def init_mail(self, config, debug=False, testing=False):
int(config.get('MAIL_DEBUG', debug)),
config.get('MAIL_MAX_EMAILS'),
config.get('MAIL_SUPPRESS_SEND', testing),
config.get('MAIL_ASCII_ATTACHMENTS', False)
config.get('MAIL_ASCII_ATTACHMENTS', False),
config.get('MAIL_TIMEOUT', smtplib.socket._GLOBAL_DEFAULT_TIMEOUT)
)

def init_app(self, app):
Expand Down
6 changes: 6 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def test_init_mail(self):
self.assertEquals(self.mail.state.__dict__, mail.__dict__)


def test_init_with_timeout(self):
with self.mail_config(timeout=5):
self.assertEquals(self.mail.timeout, 5)


class TestMessage(TestCase):

def test_initialize(self):
Expand Down Expand Up @@ -547,6 +552,7 @@ def test_empty_subject_header(self):
self.mail.send(msg)
self.assertNotIn('Subject:', msg.as_string())


class TestMail(TestCase):

def test_send(self):
Expand Down