當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。