Send mail to mutli to_addrs failed.

Change-Id: I9f8508bca8a56e5cb555cc5663def360e12355fa
Closes-Bug: #1520208
This commit is contained in:
wangzhh 2015-11-26 23:35:12 +08:00
parent f1996ff17f
commit 3a4e4380f2
2 changed files with 25 additions and 4 deletions

View File

@ -273,7 +273,7 @@ class SendEmailAction(base.Action):
# TODO(dzimine): validate parameters
# Task invocation parameters.
self.to = ', '.join(to_addrs)
self.to = to_addrs
self.subject = subject or "<No subject>"
self.body = body
@ -291,7 +291,7 @@ class SendEmailAction(base.Action):
message = text.MIMEText(self.body, _charset='utf-8')
message['Subject'] = Header(self.subject, 'utf-8')
message['From'] = self.sender
message['To'] = self.to
message['To'] = ', '.join(self.to)
try:
s = smtplib.SMTP(self.smtp_server)

View File

@ -52,7 +52,8 @@ class SendEmailActionTest(base.BaseTest):
def setUp(self):
super(SendEmailActionTest, self).setUp()
self.to_addrs = ["dz@example.com, deg@example.com", "xyz@example.com"]
self.to_addrs = ["dz@example.com", "deg@example.com",
"xyz@example.com"]
self.subject = "Multi word subject с русскими буквами"
self.body = "short multiline\nbody\nc русскими буквами"
@ -83,6 +84,26 @@ class SendEmailActionTest(base.BaseTest):
action.run()
@mock.patch('smtplib.SMTP')
def test_with_mutli_to_addrs(self, smtp):
smtp_password = "secret"
action = std.SendEmailAction(
self.from_addr, self.to_addrs,
self.smtp_server, smtp_password, self.subject, self.body
)
action.run()
@mock.patch('smtplib.SMTP')
def test_with_one_to_addr(self, smtp):
to_addr = ["dz@example.com"]
smtp_password = "secret"
action = std.SendEmailAction(
self.from_addr, to_addr,
self.smtp_server, smtp_password, self.subject, self.body
)
action.run()
@mock.patch('smtplib.SMTP')
def test_send_email(self, smtp):
action = std.SendEmailAction(
@ -100,7 +121,7 @@ class SendEmailActionTest(base.BaseTest):
self.assertEqual(
self.from_addr, sendmail.call_args[1]['from_addr'])
self.assertEqual(
self.to_addrs_str, sendmail.call_args[1]['to_addrs'])
self.to_addrs, sendmail.call_args[1]['to_addrs'])
message = parser.Parser().parsestr(sendmail.call_args[1]['msg'])