How to use the aiosmtplib.SMTPServerDisconnected 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_connect.py View on Github external
async def test_quit_then_connect_ok(smtp_client, smtpd_server):
    async with smtp_client:
        response = await smtp_client.quit()
        assert response.code == SMTPStatus.closing

        # Next command should fail
        with pytest.raises(SMTPServerDisconnected):
            response = await smtp_client.noop()

        await smtp_client.connect()

        # after reconnect, it should work again
        response = await smtp_client.noop()
        assert response.code == SMTPStatus.completed
github cole / aiosmtplib / tests / test_connect.py View on Github external
async def test_server_unexpected_disconnect(
    smtp_client, smtpd_server, smtpd_class, smtpd_response_handler_factory, monkeypatch
):
    response_handler = smtpd_response_handler_factory(
        "{} OK".format(SMTPStatus.completed),
        second_response_text="{} Bye now!".format(SMTPStatus.closing),
        close_after=True,
    )

    monkeypatch.setattr(smtpd_class, "smtp_EHLO", response_handler)

    await smtp_client.connect()
    await smtp_client.ehlo()

    with pytest.raises(SMTPServerDisconnected):
        await smtp_client.noop()
github cole / aiosmtplib / tests / test_protocol.py View on Github external
async def test_protocol_connected_check_on_read_response(monkeypatch):
    protocol = SMTPProtocol()
    monkeypatch.setattr(protocol, "transport", None)

    with pytest.raises(SMTPServerDisconnected):
        await protocol.read_response(timeout=1.0)
github cole / aiosmtplib / tests / test_protocol.py View on Github external
async def test_protocol_writer_connected_check_on_start_tls(client_tls_context):
    smtp_protocol = SMTPProtocol()

    with pytest.raises(SMTPServerDisconnected):
        await smtp_protocol.start_tls(client_tls_context)
github cole / aiosmtplib / tests / test_timeouts.py View on Github external
async def test_server_disconnected_error_after_connect_timeout(
    hostname, unused_tcp_port, sender_str, recipient_str, message_str
):
    client = SMTP(hostname=hostname, port=unused_tcp_port)

    with pytest.raises(SMTPConnectTimeoutError):
        await client.connect(timeout=0.0)

    with pytest.raises(SMTPServerDisconnected):
        await client.sendmail(sender_str, [recipient_str], message_str)
github cole / aiosmtplib / tests / test_tls.py View on Github external
async def test_starttls_disconnect_before_upgrade(
    smtp_client, smtpd_server, smtpd_class, smtpd_response_handler_factory, monkeypatch
):
    response_handler = smtpd_response_handler_factory(
        "{} Go for it".format(SMTPStatus.ready), close_after=True
    )
    monkeypatch.setattr(smtpd_class, "smtp_STARTTLS", response_handler)

    async with smtp_client:
        with pytest.raises(SMTPServerDisconnected):
            await smtp_client.starttls(validate_certs=False)