當前位置: 首頁>>代碼示例>>Python>>正文


Python EmailMessage.message方法代碼示例

本文整理匯總了Python中mailshake.EmailMessage.message方法的典型用法代碼示例。如果您正苦於以下問題:Python EmailMessage.message方法的具體用法?Python EmailMessage.message怎麽用?Python EmailMessage.message使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mailshake.EmailMessage的用法示例。


在下文中一共展示了EmailMessage.message方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_encoding

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [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>'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:27,代碼來源:test_message.py

示例2: test_multiple_message_call

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_multiple_message_call():
    """Make sure that headers are not changed when calling 
    `EmailMessage.message()` again.
    """
    email = EmailMessage('Subject', 'Content', '[email protected]',
        '[email protected]', headers={'From': '[email protected]'})
    
    message = email.message()
    assert message['From'] == '[email protected]'
    message = email.message()
    assert message['From'] == '[email protected]'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:13,代碼來源:test_message.py

示例3: test_unicode_address_header

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_unicode_address_header():
    """When a to/from/cc header contains unicode,
    make sure the email addresses are parsed correctly (especially with
    regards to commas).
    """
    email = EmailMessage('Subject', 'Content', '[email protected]',
        ['"Firstname Sürname" <[email protected]>', '[email protected]'])
    message = email.message()
    assert message['To'] == '=?utf-8?q?Firstname_S=C3=BCrname?= <[email protected]>, [email protected]'

    email = EmailMessage('Subject', 'Content', '[email protected]', 
        ['[email protected]', '"Sürname, Firstname" <[email protected]>'])
    message = email.message()
    assert message['To'] == '[email protected], =?utf-8?q?S=C3=BCrname=2C_Firstname?= <[email protected]>'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:16,代碼來源:test_message.py

示例4: test_cc

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_cc():
    email = EmailMessage('Subject', 'Content', '[email protected]',
        '[email protected]', cc='[email protected]')
    message = email.message()

    assert message['Cc'] == '[email protected]'
    assert email.get_recipients() == ['[email protected]', '[email protected]']
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:9,代碼來源:test_message.py

示例5: test_space_continuation

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_space_continuation():
    """Test for space continuation character in long (ascii) subject headers.
    """
    email = EmailMessage('Long subject lines that get wrapped should use a space continuation character to get expected behaviour in Outlook and Thunderbird',
        'Content', '[email protected]', '[email protected]')
    message = email.message()

    assert message['Subject'] == 'Long subject lines that get wrapped should use a space continuation\n character to get expected behaviour in Outlook and Thunderbird'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:10,代碼來源:test_message.py

示例6: test_from_header

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_from_header():
    """Make sure we can manually set the From header.
    """
    email = EmailMessage('Subject', 'Content', '[email protected]',
        '[email protected]', headers={'From': '[email protected]'})
    message = email.message()

    assert message['From'] == '[email protected]'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:10,代碼來源:test_message.py

示例7: test_multiple_cc_and_to

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_multiple_cc_and_to():
    email = EmailMessage('Subject', 'Content', '[email protected]',
        to=['[email protected]', '[email protected]'],
        cc=['[email protected]', '[email protected]'])
    message = email.message()

    assert message['Cc'] == '[email protected], [email protected]'
    assert email.get_recipients() == ['[email protected]', '[email protected]',
        '[email protected]', '[email protected]']
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:11,代碼來源:test_message.py

示例8: test_multiple_recipients

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_multiple_recipients():
    email = EmailMessage('Subject', 'Content', '[email protected]',
        ['[email protected]', '[email protected]'])
    message = email.message()

    assert message['Subject'].encode() == 'Subject'
    assert message.get_payload() == 'Content'
    assert message['From'] == '[email protected]'
    assert message['To'] == '[email protected], [email protected]'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:11,代碼來源:test_message.py

示例9: test_ascii

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_ascii():
    email = EmailMessage('Subject', 'Content', '[email protected]',
        '[email protected]')
    message = email.message()

    assert message['Subject'].encode() == 'Subject'
    assert message.get_payload() == 'Content'
    assert message['From'] == '[email protected]'
    assert message['To'] == '[email protected]'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:11,代碼來源:test_message.py

示例10: test_recipients_as_tuple

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_recipients_as_tuple():
    email = EmailMessage('Subject', 'Content', '[email protected]', 
        to=('[email protected]', '[email protected]'),
        cc=('[email protected]', '[email protected]'),
        bcc=('[email protected]',))
    message = email.message()

    assert message['Cc'] == '[email protected], [email protected]'
    assert email.get_recipients() == ['[email protected]', '[email protected]',
        '[email protected]', '[email protected]', '[email protected]']
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:12,代碼來源:test_message.py

示例11: test_unicode_headers

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_unicode_headers():
    headers={
        'Sender': '"Firstname Sürname" <[email protected]>',
        'Comments': 'My Sürname is non-ASCII',
    }
    email = EmailMessage(u"Gżegżółka", "Content", "[email protected]",
        "[email protected]", headers=headers)
    message = email.message()

    assert message['Subject'] == '=?utf-8?b?R8W8ZWfFvMOzxYJrYQ==?='
    assert message['Sender'] == '=?utf-8?q?Firstname_S=C3=BCrname?= <[email protected]>'
    assert message['Comments'] == '=?utf-8?q?My_S=C3=BCrname_is_non-ASCII?='
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:14,代碼來源:test_message.py

示例12: test_html

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_html():
    subject = 'hello'
    from_email = '[email protected]'
    to = '[email protected]'
    text_content = 'This is an important message.'
    html_content = '<p>This is an <strong>important</strong> message.</p>'

    email = EmailMessage(subject, text_content, from_email, to,
        html_content=html_content)
    message = email.message()

    assert message.is_multipart()
    assert message.get_content_type() == 'multipart/alternative'
    assert message.get_default_type() == 'text/plain'
    assert message.get_payload(0).get_content_type() == 'text/plain'
    assert message.get_payload(1).get_content_type() == 'text/html'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:18,代碼來源:test_message.py

示例13: test_attachments

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_attachments():
    subject = 'hello'
    from_email = '[email protected]'
    to = '[email protected]'
    text_content = 'This is an important message.'
    html_content = '<p>This is an <strong>important</strong> message.</p>'

    email = EmailMessage(subject, text_content, from_email, to,
        html_content=html_content)
    email.attach('an attachment.pdf', '%PDF-1.4.%...',
        mimetype='application/pdf')
    message = email.message()

    assert message.is_multipart()
    assert message.get_content_type() == 'multipart/mixed'
    assert message.get_default_type() == 'text/plain'
    assert message.get_payload(0).get_content_type() == 'multipart/alternative'
    assert message.get_payload(1).get_content_type() == 'application/pdf'
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:20,代碼來源:test_message.py

示例14: test_safe_mime_multipart

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [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'
    message = email.message()

    assert message['To'] == '=?iso-8859-1?q?S=FCrname=2C_Firstname?= <[email protected]>'
    assert message['Subject'].encode() == u'=?iso-8859-1?q?Message_from_Firstname_S=FCrname?='
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:20,代碼來源:test_message.py

示例15: test_header_injection

# 需要導入模塊: from mailshake import EmailMessage [as 別名]
# 或者: from mailshake.EmailMessage import message [as 別名]
def test_header_injection():
    email = EmailMessage('Subject\nInjection Test', 'Content',
        '[email protected]', '[email protected]')
    
    with pytest.raises(ValueError):
        email.message()
開發者ID:andrewnelder,項目名稱:MailShake,代碼行數:8,代碼來源:test_message.py


注:本文中的mailshake.EmailMessage.message方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。