本文整理汇总了Python中mailer.Mailer.create_mail方法的典型用法代码示例。如果您正苦于以下问题:Python Mailer.create_mail方法的具体用法?Python Mailer.create_mail怎么用?Python Mailer.create_mail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mailer.Mailer
的用法示例。
在下文中一共展示了Mailer.create_mail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_mail__unencrypted_authorized
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import create_mail [as 别名]
def test_send_mail__unencrypted_authorized(self, smtp_mock):
mail_data = MailData()
mail_data.recipients = ["[email protected]"]
mail_data.subject = "Test mail"
mail_data.body = "Test body"
mailer_config = MailerConfig()
mailer_config.smtp_host = "localhost"
mailer_config.smtp_port = 25
mailer_config.use_starttls = False
mailer_config.use_ssl = False
mailer_config.user = "Tester"
mailer_config.password = "Secret"
mailer_config.sender = "[email protected]"
mailer = Mailer()
mail = mailer.create_mail(mail_data)
mailer.send_mail(mailer_config, mail)
assert smtp_mock.call_count == 1
assert smtp_mock.call_args == ((mailer_config.smtp_host, mailer_config.smtp_port),)
assert smtp_mock.return_value.starttls.call_count == 0
assert smtp_mock.return_value.login.call_count == 1
assert smtp_mock.return_value.login.call_args == ((mailer_config.user, mailer_config.password),)
assert smtp_mock.return_value.sendmail.call_count == 1
assert smtp_mock.return_value.sendmail.call_args == ((mail["From"], mail["To"], mail.as_string()),)
assert smtp_mock.return_value.quit.call_count == 1
示例2: test_create_mail__attach_text_and_zip
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import create_mail [as 别名]
def test_create_mail__attach_text_and_zip(self):
mail = MailData()
mail.recipients = ["[email protected]"]
mail.subject = "Test mail"
mail.body = "Test body"
mail.file_attachments = ["test.txt", "test.zip"]
text_file = FileStub("TEXT")
zip_file = FileStub("BINARY")
Mailer.open_file = MagicMock(side_effect = [text_file, zip_file])
mimetypes.guess_type = MagicMock(side_effect = [("text/plain", None), ("application/zip", None)])
mailer = Mailer()
result = mailer.create_mail(mail)
self.assertEqual("[email protected]", result["To"])
self.assertEqual(mail.subject, result["Subject"])
self.assertTrue(result.is_multipart())
messages = result.get_payload()
self.assertEqual(3, len(messages))
text_message = messages[0]
self.assertEqual("text/plain", text_message.get_content_type())
self.assertEqual(mail.body, text_message.get_payload())
attachment1_message = messages[1]
self.assertEqual("text/plain", attachment1_message.get_content_type())
self.assertEqual("TEXT", attachment1_message.get_payload())
attachment2_message = messages[2]
self.assertEqual("application/zip", attachment2_message.get_content_type())
self.assertEqual(base64.b64encode("BINARY"), attachment2_message.get_payload())
示例3: test_create_mail__text_two_recipients
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import create_mail [as 别名]
def test_create_mail__text_two_recipients(self):
mail = MailData()
mail.recipients = ["[email protected]", "[email protected]"]
mail.subject = "Test mail"
mail.body = "Test body"
mailer = Mailer()
result = mailer.create_mail(mail)
self.assertEqual("[email protected], [email protected]", result["To"])
self.assertEqual(mail.subject, result["Subject"])
self.assertFalse(result.is_multipart())
self.assertEqual("text/plain", result.get_content_type())
self.assertEqual(mail.body, result.get_payload())
示例4: test_create_mail__attach_text
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import create_mail [as 别名]
def test_create_mail__attach_text(self):
mail = MailData()
mail.recipients = ["[email protected]"]
mail.subject = "Test mail"
mail.body = "Test body"
mail.file_attachments = ["test.txt"]
return_file = FileStub("This is text")
Mailer.open_file = MagicMock(return_value = return_file)
mimetypes.guess_type = MagicMock(return_value = ("text/plain", None))
mailer = Mailer()
result = mailer.create_mail(mail)
self.assertEqual("[email protected]", result["To"])
self.assertEqual(mail.subject, result["Subject"])
self.assertTrue(result.is_multipart())
messages = result.get_payload()
self.assertEqual(2, len(messages))
text_message = messages[0]
self.assertEqual("text/plain", text_message.get_content_type())
self.assertEqual(mail.body, text_message.get_payload())
attachment_message = messages[1]
self.assertEqual("text/plain", attachment_message.get_content_type())
self.assertEqual("This is text", attachment_message.get_payload())