Permalink
Browse files

Add ability to specify ESMTP options for message

  • Loading branch information...
aromanovich committed Aug 1, 2013
1 parent d1b33fb commit e1ca1e134a70cbc1566cc23aee6a9a7392573a2b
Showing with 21 additions and 2 deletions.
  1. +10 −2 flask_mail.py
  2. +11 −0 tests.py
View
@@ -165,7 +165,9 @@ def send(self, message):
if self.host:
self.host.sendmail(sanitize_address(message.sender),
message.send_to,
- message.as_string())
+ message.as_string(),
+ message.mail_options,
+ message.rcpt_options)
email_dispatched.send(message, app=current_app._get_current_object())
@@ -227,6 +229,8 @@ class Message(object):
:param date: send date
:param charset: message character set
:param extra_headers: A dictionary of additional headers for the message
+ :param mail_options: A list of ESMTP options to be used in MAIL FROM command
+ :param rcpt_options: A list of ESMTP options to be used in RCPT commands
"""
def __init__(self, subject=None,
@@ -240,7 +244,9 @@ def __init__(self, subject=None,
reply_to=None,
date=None,
charset=None,
- extra_headers=None):
+ extra_headers=None,
+ mail_options=None,
+ rcpt_options=None):
sender = sender
@@ -259,6 +265,8 @@ def __init__(self, subject=None,
self.msgId = make_msgid()
self.charset = charset
self.extra_headers = extra_headers
+ self.mail_options = mail_options or []
+ self.rcpt_options = rcpt_options or []
self.attachments = attachments or []
@property
View
@@ -66,6 +66,17 @@ def test_recipients_properly_initialized(self):
msg2.add_recipient("somebody@here.com")
self.assertEqual(len(msg2.recipients), 1)
+ def test_esmtp_options_properly_initialized(self):
+ msg = Message(subject="subject")
+ self.assertEqual(msg.mail_options, [])
+ self.assertEqual(msg.rcpt_options, [])
+
+ msg = Message(subject="subject", mail_options=['BODY=8BITMIME'])
+ self.assertEqual(msg.mail_options, ['BODY=8BITMIME'])
+
+ msg2 = Message(subject="subject", rcpt_options=['NOTIFY=SUCCESS'])
+ self.assertEqual(msg2.rcpt_options, ['NOTIFY=SUCCESS'])
+
def test_sendto_properly_set(self):
msg = Message(subject="subject", recipients=["somebody@here.com"],
cc=["cc@example.com"], bcc=["bcc@example.com"])

0 comments on commit e1ca1e1

Please sign in to comment.