How to use the aiosmtplib.SMTPConnectError 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_errors.py View on Github external
    "error_class", (SMTPServerDisconnected, SMTPConnectError, SMTPConnectTimeoutError)
)
@given(message=text())
def test_connection_exceptions(message, error_class):
    with pytest.raises(error_class) as excinfo:
        raise error_class(message)

    assert issubclass(excinfo.type, SMTPException)
    assert issubclass(excinfo.type, ConnectionError)
    assert excinfo.value.message == message
github cole / aiosmtplib / tests / test_tls.py View on Github external
async def test_tls_connection_with_cert_error(
    event_loop, tls_smtp_client, tls_smtpd_server
):
    # Don't fail on the expected exception
    event_loop.set_exception_handler(None)

    with pytest.raises(SMTPConnectError) as exception_info:
        await tls_smtp_client.connect(validate_certs=True)

    assert "CERTIFICATE_VERIFY_FAILED" in str(exception_info.value)
github cole / aiosmtplib / tests / test_tls.py View on Github external
async def test_tls_smtp_connect_to_non_tls_server(
    event_loop, tls_smtp_client, smtpd_server_port
):
    # Don't fail on the expected exception
    event_loop.set_exception_handler(None)

    with pytest.raises(SMTPConnectError):
        await tls_smtp_client.connect(port=smtpd_server_port)
    assert not tls_smtp_client.is_connected
github cole / aiosmtplib / tests / test_connect.py View on Github external
async def test_connect_error_with_no_server(hostname, unused_tcp_port):
    client = SMTP(hostname=hostname, port=unused_tcp_port)

    with pytest.raises(SMTPConnectError):
        # SMTPConnectTimeoutError vs SMTPConnectError here depends on
        # processing time.
        await client.connect(timeout=1.0)
github cole / aiosmtplib / tests / test_connect.py View on Github external
async def test_bad_connect_response_raises_error(
    smtp_client, smtpd_server, smtpd_class, smtpd_response_handler_factory, monkeypatch
):
    response_handler = smtpd_response_handler_factory(
        "{} retry in 5 minutes".format(SMTPStatus.domain_unavailable), close_after=True
    )
    monkeypatch.setattr(smtpd_class, "_handle_client", response_handler)

    with pytest.raises(SMTPConnectError):
        await smtp_client.connect()

    assert smtp_client.transport is None
    assert smtp_client.protocol is None