Skip to content
Browse files

Merge pull request #48 from aromanovich/master

Add ability to specify ESMTP options and envelope FROM address
  • Loading branch information...
2 parents f54e461 + 162af38 commit a02b7afb488bbe9e632614880dd499e74c04ee1d @mattupstate committed
Showing with 24 additions and 4 deletions.
  1. +13 −4 flask_mail.py
  2. +11 −0 tests.py
View
17 flask_mail.py
@@ -145,10 +145,11 @@ def configure_host(self):
return host
- def send(self, message):
+ def send(self, message, envelope_from=None):
"""Verifies and sends message.
:param message: Message instance.
+ :param envelope_from: Email address to be used in MAIL FROM command.
"""
assert message.recipients, "No recipients have been added"
@@ -163,9 +164,11 @@ def send(self, message):
message.date = time.time()
if self.host:
- self.host.sendmail(sanitize_address(message.sender),
+ self.host.sendmail(sanitize_address(envelope_from or 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 +230,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 +245,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 +266,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
11 tests.py
@@ -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 a02b7af

Please sign in to comment.
Something went wrong with that request. Please try again.