How to use the aiosmtplib.email.extract_recipients function in aiosmtplib

To help you get started, we’ve selected a few aiosmtplib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cole / aiosmtplib / tests / test_email_utils.py View on Github external
def test_extract_recipients_invalid_email():
    message = EmailMessage()
    message["Cc"] = "me"

    recipients = extract_recipients(message)

    assert recipients == ["me"]
github cole / aiosmtplib / tests / test_email_utils.py View on Github external
def test_extract_recipients_valueerror_on_multiple_resent_message():
    message = EmailMessage()
    message["Resent-Date"] = "Mon, 20 Nov 2016 21:04:27 -0000"
    message["Resent-Date"] = "Mon, 20 Nov 2017 21:04:27 -0000"

    with pytest.raises(ValueError):
        extract_recipients(message)
github cole / aiosmtplib / tests / test_email_utils.py View on Github external
def test_extract_recipients(
    mime_to_header,
    mime_cc_header,
    compat32_to_header,
    compat32_cc_header,
    expected_recipients,
):
    mime_message = EmailMessage()
    mime_message["To"] = mime_to_header
    mime_message["Cc"] = mime_cc_header

    mime_recipients = extract_recipients(mime_message)

    assert mime_recipients == expected_recipients

    compat32_message = Message()
    compat32_message["To"] = compat32_to_header
    compat32_message["Cc"] = compat32_cc_header

    compat32_recipients = extract_recipients(compat32_message)

    assert compat32_recipients == expected_recipients
github cole / aiosmtplib / tests / test_email_utils.py View on Github external
compat32_cc_header,
    expected_recipients,
):
    mime_message = EmailMessage()
    mime_message["To"] = mime_to_header
    mime_message["Cc"] = mime_cc_header

    mime_recipients = extract_recipients(mime_message)

    assert mime_recipients == expected_recipients

    compat32_message = Message()
    compat32_message["To"] = compat32_to_header
    compat32_message["Cc"] = compat32_cc_header

    compat32_recipients = extract_recipients(compat32_message)

    assert compat32_recipients == expected_recipients
github cole / aiosmtplib / tests / test_email_utils.py View on Github external
def test_extract_recipients_resent_message():
    message = EmailMessage()
    message["To"] = "bob@example.com"
    message["Cc"] = "claire@example.com"
    message["Bcc"] = "dustin@example.com"

    message["Resent-Date"] = "Mon, 20 Nov 2017 21:04:27 -0000"
    message["Resent-To"] = "eliza@example.com"
    message["Resent-Cc"] = "fred@example.com"
    message["Resent-Bcc"] = "gina@example.com"

    recipients = extract_recipients(message)

    assert message["Resent-To"] in recipients
    assert message["Resent-Cc"] in recipients
    assert message["Resent-Bcc"] in recipients
    assert message["To"] not in recipients
    assert message["Cc"] not in recipients
    assert message["Bcc"] not in recipients
github cole / aiosmtplib / tests / test_email_utils.py View on Github external
def test_extract_recipients_includes_bcc():
    message = EmailMessage()
    message["Bcc"] = "alice@example.com"

    recipients = extract_recipients(message)

    assert recipients == [message["Bcc"]]
github cole / aiosmtplib / tests / test_email_utils.py View on Github external
def test_extract_recipients_with_iterable_of_strings():
    message = EmailMessage()
    message["To"] = ("me@example.com", "you")

    recipients = extract_recipients(message)

    assert recipients == ["me@example.com", "you"]
github cole / aiosmtplib / aiosmtplib / smtp.py View on Github external
:raises SMTPResponseException: on invalid response
        """
        if mail_options is None:
            mail_options = []
        else:
            mail_options = list(mail_options)

        if sender is None:
            sender = extract_sender(message)
        if not sender:
            raise ValueError("No From header provided in message")

        if isinstance(recipients, str):
            recipients = [recipients]
        elif recipients is None:
            recipients = extract_recipients(message)
        if not recipients:
            raise ValueError("No recipient headers provided in message")

        # Make sure we've done an EHLO for extension checks
        await self._ehlo_or_helo_if_needed()

        try:
            sender.encode("ascii")
            "".join(recipients).encode("ascii")
        except UnicodeEncodeError:
            utf8_required = True
        else:
            utf8_required = False

        if utf8_required:
            if not self.supports_extension("smtputf8"):