当前位置: 首页>>代码示例>>Python>>正文


Python Message.to_message方法代码示例

本文整理汇总了Python中pyramid_mailer.message.Message.to_message方法的典型用法代码示例。如果您正苦于以下问题:Python Message.to_message方法的具体用法?Python Message.to_message怎么用?Python Message.to_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid_mailer.message.Message的用法示例。


在下文中一共展示了Message.to_message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_attach_as_html

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_attach_as_html(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = 'iso-8859-1'
        text_encoded = b'LaPe\xf1a'
        html_encoded = b'<p>' + text_encoded + b'</p>'
        html_text = html_encoded.decode(charset)
        transfer_encoding = 'quoted-printable'
        html = Attachment(
            data=html_text,
            transfer_encoding=transfer_encoding
            )
        msg = Message(
            subject="testing",
            sender="[email protected]",
            recipients=["[email protected]"],
            html=html,
            )

        html_part = msg.to_message()

        self.assertEqual(
            html_part['Content-Type'],
            'text/html; charset="iso-8859-1"'
            )
        self.assertEqual(
            html_part['Content-Transfer-Encoding'],
            transfer_encoding
            )
        self.assertEqual(
            html_part.get_payload(),
            _qencode(html_encoded).decode('ascii')
            )
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:36,代码来源:test_message.py

示例2: test_attach_as_body

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_attach_as_body(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = 'iso-8859-1'
        text_encoded = b'LaPe\xf1a'
        text = text_encoded.decode(charset)
        transfer_encoding = 'quoted-printable'
        body = Attachment(
            data=text,
            transfer_encoding=transfer_encoding
            )
        msg = Message(
            subject="testing",
            sender="[email protected]",
            recipients=["[email protected]"],
            body=body
            )
        body_part = msg.to_message()

        self.assertEqual(
            body_part['Content-Type'],
            'text/plain; charset="iso-8859-1"'
            )
        self.assertEqual(
            body_part['Content-Transfer-Encoding'],
            transfer_encoding
            )
        self.assertEqual(
            body_part.get_payload(),
            _qencode(text_encoded).decode('ascii')
            )
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:34,代码来源:test_message.py

示例3: test_attach_as_body_and_html_latin1

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_attach_as_body_and_html_latin1(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = "iso-8859-1"
        text_encoded = b"LaPe\xf1a"
        text = text_encoded.decode(charset)
        html_encoded = b"<p>" + text_encoded + b"</p>"
        html_text = html_encoded.decode(charset)
        transfer_encoding = "quoted-printable"
        body = Attachment(data=text, transfer_encoding=transfer_encoding)
        html = Attachment(data=html_text, transfer_encoding=transfer_encoding)
        msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body=body, html=html)
        message = msg.to_message()
        body_part, html_part = message.get_payload()

        self.assertEqual(body_part["Content-Type"], 'text/plain; charset="iso-8859-1"')
        self.assertEqual(body_part["Content-Transfer-Encoding"], transfer_encoding)
        payload = body_part.get_payload()
        self.assertEqual(payload, _qencode(text_encoded).decode("ascii"))

        self.assertEqual(html_part["Content-Type"], 'text/html; charset="iso-8859-1"')
        self.assertEqual(html_part["Content-Transfer-Encoding"], transfer_encoding)
        payload = html_part.get_payload()
        self.assertEqual(payload, _qencode(html_encoded).decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:27,代码来源:test_message.py

示例4: test_attach_as_body_and_html_utf8

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_attach_as_body_and_html_utf8(self):
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = "utf-8"
        # greek small letter iota with dialtyika and tonos; this character
        # cannot be encoded to either ascii or latin-1, so utf-8 is chosen
        text_encoded = b"\xce\x90"
        text = text_encoded.decode(charset)
        html_encoded = b"<p>" + text_encoded + b"</p>"
        html_text = html_encoded.decode(charset)
        transfer_encoding = "quoted-printable"
        body = Attachment(data=text, transfer_encoding=transfer_encoding)
        html = Attachment(data=html_text, transfer_encoding=transfer_encoding)
        msg = Message(subject="testing", sender="[email protected]", recipients=["[email protected]"], body=body, html=html)
        message = msg.to_message()
        body_part, html_part = message.get_payload()

        self.assertEqual(body_part["Content-Type"], 'text/plain; charset="utf-8"')

        self.assertEqual(body_part["Content-Transfer-Encoding"], transfer_encoding)

        payload = body_part.get_payload()
        self.assertEqual(payload, _qencode(text_encoded).decode("ascii"))

        self.assertEqual(html_part["Content-Type"], 'text/html; charset="utf-8"')
        self.assertEqual(html_part["Content-Transfer-Encoding"], transfer_encoding)
        payload = html_part.get_payload()
        self.assertEqual(payload, _qencode(html_encoded).decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:31,代码来源:test_message.py

示例5: test_to_message_multipart_with_qpencoding

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
 def test_to_message_multipart_with_qpencoding(self):
     from pyramid_mailer.message import Message, Attachment
     response = Message(
         recipients=['To'],
         sender='From',
         subject='Subject',
         body='Body',
         html='Html'
         )
     this = os.path.abspath(__file__)
     with open(this, 'rb') as data:
         attachment = Attachment(
             filename=this,
             content_type='application/octet-stream',
             disposition='disposition',
             transfer_encoding='quoted-printable',
             data=data,
             )
         response.attach(attachment)
         message = response.to_message()
         payload = message.get_payload()[1]
     self.assertEqual(
         payload.get('Content-Transfer-Encoding'),
         'quoted-printable'
         )
     self.assertEqual(
         payload.get_payload(),
         _qencode(self._read_filedata(this,'rb')).decode('ascii')
         )
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:31,代码来源:test_message.py

示例6: test_cc_without_recipients_2

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_cc_without_recipients_2(self):

        from pyramid_mailer.message import Message

        msg = Message(subject="testing", sender="[email protected]", body="testing", cc=["[email protected]"])
        response = msg.to_message()
        self.assertTrue("Cc: [email protected]" in text_type(response))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:9,代码来源:test_message.py

示例7: test_attach_as_html

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_attach_as_html(self):
        import codecs
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment

        charset = 'latin-1'
        text_encoded = b('LaPe\xf1a')
        text = text_encoded.decode(charset)
        text_html = '<p>' + text + '</p>'
        transfer_encoding = 'quoted-printable'
        html = Attachment(data=text_html,
                          transfer_encoding=transfer_encoding)
        msg = Message(subject="testing",
                      sender="[email protected]",
                      recipients=["[email protected]"],
                      html=html)
        html_part = msg.to_message()

        self.assertEqual(
            html_part['Content-Type'], 'text/html')
        self.assertEqual(
            html_part['Content-Transfer-Encoding'], transfer_encoding)
        self.assertEqual(html_part.get_payload(),
                         codecs.getencoder('quopri_codec')(
                             text_html.encode(charset))[0].decode('ascii'))
开发者ID:ccomb,项目名称:pyramid_mailer,代码行数:27,代码来源:tests.py

示例8: _send_annotation

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
 def _send_annotation(self, body, subject, recipients):
     body = body.decode('utf8')
     subject = subject.decode('utf8')
     message = Message(subject=subject,
                       recipients=recipients,
                       body=body)
     self.mailer.send(message)
     log.info('sent: %s', message.to_message().as_string())
开发者ID:ercchy,项目名称:h,代码行数:10,代码来源:notifier.py

示例9: test_to_message_with_html_attachment

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_to_message_with_html_attachment(self):
        from pyramid_mailer.message import Message, Attachment

        response = Message(recipients=["To"], sender="From", subject="Subject", body="Body")
        attachment = Attachment(data=b"data", content_type="text/html")
        response.attach(attachment)
        message = response.to_message()
        att_payload = message.get_payload()[1]
        self.assertEqual(att_payload["Content-Type"], 'text/html; charset="us-ascii"')
        self.assertEqual(att_payload.get_payload(), _bencode(b"data").decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:12,代码来源:test_message.py

示例10: test_to_message_with_binary_attachment

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_to_message_with_binary_attachment(self):
        from pyramid_mailer.message import Message, Attachment

        response = Message(recipients=["To"], sender="From", subject="Subject", body="Body")
        data = os.urandom(100)
        attachment = Attachment(data=data, content_type="application/octet-stream")
        response.attach(attachment)
        message = response.to_message()
        att_payload = message.get_payload()[1]
        self.assertEqual(att_payload["Content-Type"], "application/octet-stream")
        self.assertEqual(att_payload.get_payload(), _bencode(data).decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:13,代码来源:test_message.py

示例11: test_bcc_without_recipients

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_bcc_without_recipients(self):

        from pyramid_mailer.message import Message
        from pyramid_mailer.mailer import Mailer

        msg = Message(subject="testing", sender="[email protected]", body="testing", bcc=["[email protected]"])
        mailer = Mailer()
        msgid = mailer.send(msg)
        response = msg.to_message()

        self.assertFalse("Bcc: [email protected]" in text_type(response))
        self.assertTrue(msgid)
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:14,代码来源:test_message.py

示例12: test_message_is_quoted_printable_with_text_body

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_message_is_quoted_printable_with_text_body(self):
        from pyramid_mailer.message import Message

        msg = Message(
            recipients=['[email protected]'],
            subject="testing",
            sender="[email protected]",
            body="THISSHOULDBEINMESSAGEBODY",
            )

        response = msg.to_message()
        self.assertTrue("THISSHOULDBEINMESSAGEBODY" in text_type(response))
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:14,代码来源:test_message.py

示例13: test_to_message_multiple_to_recipients

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
 def test_to_message_multiple_to_recipients(self):
     from pyramid_mailer.message import Message
     response = Message(
         subject="Subject",
         sender="From",
         recipients=["[email protected]", "[email protected]"],
         body="Body",
         html="Html",
         )
     message = response.to_message()
     self.assertEqual(text_type(message['To']),
                      '[email protected], [email protected]')
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:14,代码来源:test_message.py

示例14: test_extra_headers

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_extra_headers(self):

        from pyramid_mailer.message import Message

        msg = Message(
            subject="testing",
            sender="[email protected]",
            recipients=["[email protected]"],
            body="testing",
            extra_headers=[('X-Foo', 'Joe')]
            )

        response = msg.to_message()
        self.assertTrue("X-Foo: Joe" in text_type(response))
开发者ID:Pylons,项目名称:pyramid_mailer,代码行数:16,代码来源:test_message.py

示例15: test_to_message_multipart_with_qpencoding

# 需要导入模块: from pyramid_mailer.message import Message [as 别名]
# 或者: from pyramid_mailer.message.Message import to_message [as 别名]
    def test_to_message_multipart_with_qpencoding(self):
        from pyramid_mailer.message import Message, Attachment

        response = Message(recipients=["To"], sender="From", subject="Subject", body="Body", html="Html")
        this = os.path.abspath(__file__)
        data = open(this, "rb")
        attachment = Attachment(
            filename=this,
            content_type="application/octet-stream",
            disposition="disposition",
            transfer_encoding="quoted-printable",
            data=data,
        )
        response.attach(attachment)
        message = response.to_message()
        payload = message.get_payload()[1]
        self.assertEqual(payload.get("Content-Transfer-Encoding"), "quoted-printable")
        self.assertEqual(payload.get_payload(), _qencode(self._read_filedata(this, "rb")).decode("ascii"))
开发者ID:kristianbenoit,项目名称:pyramid_mailer,代码行数:20,代码来源:test_message.py


注:本文中的pyramid_mailer.message.Message.to_message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。