本文整理匯總了Python中mailshake.EmailMessage.encoding方法的典型用法代碼示例。如果您正苦於以下問題:Python EmailMessage.encoding方法的具體用法?Python EmailMessage.encoding怎麽用?Python EmailMessage.encoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mailshake.EmailMessage
的用法示例。
在下文中一共展示了EmailMessage.encoding方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_encoding
# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import encoding [as 別名]
def test_encoding():
"""Encode body correctly with other encodings
than utf-8
"""
email = EmailMessage('Subject', 'Firstname Sürname is a great guy.',
'[email protected]', '[email protected]')
email.encoding = 'iso-8859-1'
message = email.message()
assert message.as_string().startswith('Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: [email protected]\nTo: [email protected]')
assert message.get_payload() == 'Firstname S=FCrname is a great guy.'
# Make sure MIME attachments also works correctly with other encodings than utf-8
text_content = 'Firstname Sürname is a great guy.'
html_content = '<p>Firstname Sürname is a <strong>great</strong> guy.</p>'
email = EmailMessage('Subject', text_content, '[email protected]',
'[email protected]', html_content=html_content)
email.encoding = 'iso-8859-1'
message = email.message()
assert message.get_payload(0).as_string() == \
'Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\nFirstname S=FCrname is a great guy.'
assert message.get_payload(1).as_string() == \
'Content-Type: text/html; charset="iso-8859-1"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\n<p>Firstname S=FCrname is a <strong>great</strong> guy.</p>'
示例2: test_safe_mime_multipart
# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import encoding [as 別名]
def test_safe_mime_multipart():
"""Make sure headers can be set with a different encoding than utf-8 in
SafeMIMEMultipart as well
"""
subject = 'Message from Firstname Sürname'
from_email = '[email protected]'
to = '"Sürname, Firstname" <[email protected]>'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
headers = {"Date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"}
email = EmailMessage(subject, text_content, from_email, to,
html_content=html_content, headers=headers)
email.encoding = 'iso-8859-1'
email.render()