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


Python envelope.Envelope类代码示例

本文整理汇总了Python中envelopes.envelope.Envelope的典型用法代码示例。如果您正苦于以下问题:Python Envelope类的具体用法?Python Envelope怎么用?Python Envelope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_to_mime_message_with_data

    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")
开发者ID:blueicesir,项目名称:envelopes,代码行数:27,代码来源:test_envelope.py

示例2: test_add_header

    def test_add_header(self):
        msg = self._dummy_message()
        msg.pop('headers')
        envelope = Envelope(**msg)

        envelope.add_header('X-Spam', 'eggs')
        assert envelope.headers == {'X-Spam': 'eggs'}
开发者ID:zefciu,项目名称:envelopes,代码行数:7,代码来源:test_envelope.py

示例3: test_add_bcc_addr

    def test_add_bcc_addr(self):
        msg = self._dummy_message()
        msg.pop("bcc_addr")

        envelope = Envelope(**msg)
        envelope.add_bcc_addr("[email protected]")
        assert envelope.bcc_addr == ["[email protected]"]
开发者ID:blueicesir,项目名称:envelopes,代码行数:7,代码来源:test_envelope.py

示例4: test_to_mime_message_with_data

    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')
开发者ID:zefciu,项目名称:envelopes,代码行数:31,代码来源:test_envelope.py

示例5: test_repr

    def test_repr(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        assert envelope.__repr__() == (
            u"""<Envelope from="Example From <[email protected]>" """
            u"""to="Example To <[email protected]>" """
            u"""subject="I'm a helicopter!">"""
        )
开发者ID:blueicesir,项目名称:envelopes,代码行数:9,代码来源:test_envelope.py

示例6: test_to_mime_message_with_many_to_addresses

    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]m>"
        assert mime_msg["To"] == to_header
开发者ID:blueicesir,项目名称:envelopes,代码行数:10,代码来源:test_envelope.py

示例7: test_send

    def test_send(self):
        envelope = Envelope(
            from_addr="[email protected]",
            to_addr="[email protected]",
            subject="Testing envelopes!",
            text_body="Just a testy test.",
        )

        conn, result = envelope.send(host="localhost")
        assert conn._conn is not None
        assert len(conn._conn._call_stack.get("sendmail", [])) == 1
开发者ID:blueicesir,项目名称:envelopes,代码行数:11,代码来源:test_envelope.py

示例8: test_send

    def test_send(self):
        envelope = Envelope(
            from_addr='[email protected]',
            to_addr='[email protected]',
            subject='Testing envelopes!',
            text_body='Just a testy test.'
        )

        conn, result = envelope.send(host='localhost')
        assert conn._conn is not None
        assert len(conn._conn._call_stack.get('sendmail', [])) == 1
开发者ID:zefciu,项目名称:envelopes,代码行数:11,代码来源:test_envelope.py

示例9: test_to_mime_message_with_no_data

    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
开发者ID:zefciu,项目名称:envelopes,代码行数:13,代码来源:test_envelope.py

示例10: test_to_mime_message_with_no_data

    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
开发者ID:blueicesir,项目名称:envelopes,代码行数:13,代码来源:test_envelope.py

示例11: test_to_mime_message_unicode

    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')
开发者ID:zefciu,项目名称:envelopes,代码行数:48,代码来源:test_envelope.py

示例12: test_send

    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] != ''
开发者ID:dec0dedab0de,项目名称:envelopes,代码行数:16,代码来源:test_conn.py

示例13: test_send

    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] != ""
开发者ID:blueicesir,项目名称:envelopes,代码行数:18,代码来源:test_conn.py

示例14: test_to_mime_message_with_many_to_addresses

    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
开发者ID:zefciu,项目名称:envelopes,代码行数:18,代码来源:test_envelope.py

示例15: test_to_mime_message_unicode

    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")
开发者ID:blueicesir,项目名称:envelopes,代码行数:42,代码来源:test_envelope.py


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