本文整理汇总了Python中envelopes.envelope.Envelope.to_mime_message方法的典型用法代码示例。如果您正苦于以下问题:Python Envelope.to_mime_message方法的具体用法?Python Envelope.to_mime_message怎么用?Python Envelope.to_mime_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类envelopes.envelope.Envelope
的用法示例。
在下文中一共展示了Envelope.to_mime_message方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_mime_message_with_data
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_with_data(self):
msg = self._dummy_message()
envelope = Envelope(**msg)
mime_msg = envelope.to_mime_message()
assert mime_msg is not None
assert mime_msg['Subject'] == msg['subject']
assert mime_msg['To'] == 'Example To <[email protected]>'
assert mime_msg['From'] == 'Example From <[email protected]>'
cc_header = (
'[email protected],'
'Example CC2 <[email protected]>,'
'Example CC3 <[email protected]>'
)
assert mime_msg['CC'] == cc_header
assert 'BCC' not in mime_msg
assert mime_msg['Reply-To'] == msg['headers']['Reply-To']
assert mime_msg['X-Mailer'] == msg['headers']['X-Mailer']
mime_msg_parts = [part for part in mime_msg.walk()]
assert len(mime_msg_parts) == 3
text_part, html_part = mime_msg_parts[1:]
assert text_part.get_content_type() == 'text/plain'
assert text_part.get_payload(decode=True) == msg['text_body'].encode('utf-8')
assert html_part.get_content_type() == 'text/html'
assert html_part.get_payload(decode=True) == msg['html_body'].encode('utf-8')
示例2: test_to_mime_message_with_data
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_with_data(self):
msg = self._dummy_message()
envelope = Envelope(**msg)
mime_msg = envelope.to_mime_message()
assert mime_msg is not None
assert mime_msg["Subject"] == msg["subject"]
assert mime_msg["To"] == "Example To <[email protected]>"
assert mime_msg["From"] == "Example From <[email protected]>"
cc_header = "[email protected]," "Example CC2 <[email protected]>," "Example CC3 <[email protected]>"
assert mime_msg["CC"] == cc_header
assert "BCC" not in mime_msg
assert mime_msg["Reply-To"] == msg["headers"]["Reply-To"]
assert mime_msg["X-Mailer"] == msg["headers"]["X-Mailer"]
mime_msg_parts = [part for part in mime_msg.walk()]
assert len(mime_msg_parts) == 3
text_part, html_part = mime_msg_parts[1:]
assert text_part.get_content_type() == "text/plain"
assert text_part.get_payload(decode=True) == msg["text_body"].encode("utf-8")
assert html_part.get_content_type() == "text/html"
assert html_part.get_payload(decode=True) == msg["html_body"].encode("utf-8")
示例3: test_to_mime_message_with_many_to_addresses
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_with_many_to_addresses(self):
msg = self._dummy_message()
msg["to_addr"] = ["[email protected]", "Example To2 <[email protected]>", ("[email protected]", "Example To3")]
envelope = Envelope(**msg)
mime_msg = envelope.to_mime_message()
assert mime_msg is not None
to_header = "[email protected]," "Example To2 <[email protected]>," "Example To3 <[email protected]>"
assert mime_msg["To"] == to_header
示例4: test_to_mime_message_with_no_data
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_with_no_data(self):
envelope = Envelope()
mime_msg = envelope.to_mime_message()
assert mime_msg["Subject"] == ""
assert mime_msg["To"] == ""
assert mime_msg["From"] == ""
assert "CC" not in mime_msg
assert "BCC" not in mime_msg
mime_msg_parts = [part for part in mime_msg.walk()]
assert len(mime_msg_parts) == 1
示例5: test_to_mime_message_with_no_data
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_with_no_data(self):
envelope = Envelope()
mime_msg = envelope.to_mime_message()
assert mime_msg['Subject'] == ''
assert mime_msg['To'] == ''
assert mime_msg['From'] == ''
assert 'CC' not in mime_msg
assert 'BCC' not in mime_msg
mime_msg_parts = [part for part in mime_msg.walk()]
assert len(mime_msg_parts) == 1
示例6: test_to_mime_message_unicode
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_unicode(self):
msg = {
'to_addr': ('[email protected]', u'ęóąśłżźćń'),
'from_addr': ('[email protected]', u'ęóąśłżźćń'),
'subject': u'ęóąśłżźćń',
'html_body': u'ęóąśłżźćń',
'text_body': u'ęóąśłżźćń',
'cc_addr': [
('[email protected]', u'ęóąśłżźćń')
],
'bcc_addr': [
u'ęóąśłżźćń <[email protected]>'
],
'headers': {
'X-Test': u'ęóąśłżźćń'
},
'charset': 'utf-8'
}
envelope = Envelope(**msg)
def enc_addr_header(name, email):
header = Header(name)
header.append(email)
return header.encode()
mime_msg = envelope.to_mime_message()
assert mime_msg is not None
assert mime_msg['Subject'] == Header(msg['subject'], 'utf-8').encode()
assert mime_msg['To'] == enc_addr_header(u'ęóąśłżźćń', '<[email protected]>')
assert mime_msg['From'] == enc_addr_header(u'ęóąśłżźćń', '<[email protected]>')
assert mime_msg['CC'] == enc_addr_header(u'ęóąśłżźćń', '<[email protected]>')
assert 'BCC' not in mime_msg
assert mime_msg['X-Test'] == Header(msg['headers']['X-Test'], 'utf-8').encode()
mime_msg_parts = [part for part in mime_msg.walk()]
assert len(mime_msg_parts) == 3
text_part, html_part = mime_msg_parts[1:]
assert text_part.get_content_type() == 'text/plain'
assert text_part.get_payload(decode=True) == msg['text_body'].encode('utf-8')
assert html_part.get_content_type() == 'text/html'
assert html_part.get_payload(decode=True) == msg['html_body'].encode('utf-8')
示例7: test_send
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_send(self):
conn = SMTP('localhost')
msg = self._dummy_message()
envelope = Envelope(**msg)
mime_msg = envelope.to_mime_message()
conn.send(envelope)
assert conn._conn is not None
assert len(conn._conn._call_stack.get('sendmail', [])) == 1
call_args = conn._conn._call_stack['sendmail'][0][0]
assert len(call_args) == 3
assert call_args[0] == mime_msg['From']
assert call_args[1] == mime_msg['To']
assert call_args[2] != ''
示例8: test_to_mime_message_with_many_to_addresses
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_with_many_to_addresses(self):
msg = self._dummy_message()
msg['to_addr'] = [
'[email protected]',
'Example To2 <[email protected]>',
('[email protected]', 'Example To3')
]
envelope = Envelope(**msg)
mime_msg = envelope.to_mime_message()
assert mime_msg is not None
to_header = (
'[email protected],'
'Example To2 <[email protected]>,'
'Example To3 <[email protected]>'
)
assert mime_msg['To'] == to_header
示例9: test_send
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_send(self):
conn = SMTP("localhost")
msg = self._dummy_message()
envelope = Envelope(**msg)
mime_msg = envelope.to_mime_message()
conn.send(envelope)
assert conn._conn is not None
assert len(conn._conn._call_stack.get("sendmail", [])) == 1
call_args = conn._conn._call_stack["sendmail"][0][0]
assert len(call_args) == 3
assert call_args[0] == mime_msg["From"]
assert call_args[1] == [
envelope._addrs_to_header([addr]) for addr in envelope._to + envelope._cc + envelope._bcc
]
assert call_args[2] != ""
示例10: test_to_mime_message_unicode
# 需要导入模块: from envelopes.envelope import Envelope [as 别名]
# 或者: from envelopes.envelope.Envelope import to_mime_message [as 别名]
def test_to_mime_message_unicode(self):
msg = {
"to_addr": ("[email protected]", u"ęóąśłżźćń"),
"from_addr": ("[email protected]", u"ęóąśłżźćń"),
"subject": u"ęóąśłżźćń",
"html_body": u"ęóąśłżźćń",
"text_body": u"ęóąśłżźćń",
"cc_addr": [("[email protected]", u"ęóąśłżźćń")],
"bcc_addr": [u"ęóąśłżźćń <[email protected]>"],
"headers": {"X-Test": u"ęóąśłżźćń"},
"charset": "utf-8",
}
envelope = Envelope(**msg)
def enc_addr_header(name, email):
header = Header(name)
header.append(email)
return header.encode()
mime_msg = envelope.to_mime_message()
assert mime_msg is not None
assert mime_msg["Subject"] == Header(msg["subject"], "utf-8").encode()
assert mime_msg["To"] == enc_addr_header(u"ęóąśłżźćń", "<[email protected]>")
assert mime_msg["From"] == enc_addr_header(u"ęóąśłżźćń", "<[email protected]>")
assert mime_msg["CC"] == enc_addr_header(u"ęóąśłżźćń", "<[email protected]>")
assert "BCC" not in mime_msg
assert mime_msg["X-Test"] == Header(msg["headers"]["X-Test"], "utf-8").encode()
mime_msg_parts = [part for part in mime_msg.walk()]
assert len(mime_msg_parts) == 3
text_part, html_part = mime_msg_parts[1:]
assert text_part.get_content_type() == "text/plain"
assert text_part.get_payload(decode=True) == msg["text_body"].encode("utf-8")
assert html_part.get_content_type() == "text/html"
assert html_part.get_payload(decode=True) == msg["html_body"].encode("utf-8")