How to use the aiosmtplib.SMTPStatus 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_tls.py View on Github external
async def test_starttls(smtp_client, smtpd_server):
    async with smtp_client:
        response = await smtp_client.starttls(validate_certs=False)

        assert response.code == SMTPStatus.ready

        # Make sure our state has been cleared
        assert not smtp_client.esmtp_extensions
        assert not smtp_client.supported_auth_methods
        assert not smtp_client.supports_esmtp

        # Make sure our connection was actually upgraded. ssl protocol transport is
        # private in UVloop, so just check the class name.
        assert "SSL" in type(smtp_client.transport).__name__

        response = await smtp_client.ehlo()
        assert response.code == SMTPStatus.completed
github cole / aiosmtplib / tests / test_connect.py View on Github external
async def close_during_read_response(smtpd, *args, **kwargs):
        # Read one line of data, then cut the connection.
        await smtpd.push(
            "{} End data with .".format(SMTPStatus.start_input)
        )

        await smtpd._reader.readline()
        smtpd.transport.close()
github cole / aiosmtplib / tests / test_commands.py View on Github external
async def test_badly_encoded_text_response(
    smtp_client, smtpd_server, smtpd_class, bad_data_response_handler, monkeypatch
):
    monkeypatch.setattr(smtpd_class, "smtp_NOOP", bad_data_response_handler)

    async with smtp_client:
        response = await smtp_client.noop()

    assert response.code == SMTPStatus.completed
github cole / aiosmtplib / tests / test_asyncio.py View on Github external
async def test_many_commands_with_gather(
    monkeypatch, smtp_client, smtpd_server, smtpd_class, smtpd_response_handler
):
    """
    Tests that appropriate locks are in place to prevent commands confusing each other.
    """
    response_handler = smtpd_response_handler(
        "{}  Alice Smith ".format(SMTPStatus.completed)
    )
    monkeypatch.setattr(smtpd_class, "smtp_EXPN", response_handler)

    async with smtp_client:
        tasks = [
            smtp_client.ehlo(),
            smtp_client.helo(),
            smtp_client.noop(),
            smtp_client.vrfy("foo@bar.com"),
            smtp_client.expn("users@example.com"),
            smtp_client.mail("alice@example.com"),
            smtp_client.help(),
        ]
        results = await asyncio.gather(*tasks)

    for result in results[:-1]:
github cole / aiosmtplib / tests / test_server.py View on Github external
def test_mock_server_starttls_with_smtplib(preset_server):
    smtp = smtplib.SMTP()
    smtp._host = preset_server.hostname  # Hack around smtplib SNI bug
    smtp.connect(host=preset_server.hostname, port=preset_server.port)
    preset_server.responses.append(b'\n'.join([
        b'250-localhost, hello',
        b'250-SIZE 100000',
        b'250 STARTTLS',
    ]))

    code, message = smtp.ehlo()
    assert code == SMTPStatus.completed

    preset_server.responses.append(b'220 ready for TLS')
    code, message = smtp.starttls()
    assert code == SMTPStatus.ready

    # make sure our connection was actually upgraded
    assert isinstance(smtp.sock, ssl.SSLSocket)

    preset_server.responses.append(b'250 all good')
    code, message = smtp.ehlo()
    assert code == SMTPStatus.completed