Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Non-OK SMTP responses #9

Open
tabascoterrier opened this issue Jul 9, 2021 · 1 comment
Open

[Feature Request] Non-OK SMTP responses #9

tabascoterrier opened this issue Jul 9, 2021 · 1 comment

Comments

@tabascoterrier
Copy link

tabascoterrier commented Jul 9, 2021

It's great to see this project revived!

I'm in a position where I could really do with being able to trigger error responses to certain emails (e.g. '550 Mailbox unavailable' and '421 Service not available') to aid in testing.

I tried to do this myself by adding a handle_RCPT handler into smtp.py's AsyncMessage class:

# If the address contains "smtp_response_nnn", return a suitable response code
async def handle_RCPT(self, server, session, envelope, address, rcpt_options):
    if 'smtpresponse_421' in address:
        return '421 Service not available'

    if 'smtpresponse_550' in address:
        return '550 Mailbox unavailable'

    envelope.rcpt_tos.append(address)
    return '250 OK'

This does return the expected SMTP response codes, but now the handle_message handler no longer fires so the message doesn't make it into the DB, and at this point my lack of knowledge of aiosmtpd and async Python becomes very obvious :)

It turns out this does work fine after all.

@msztolcman
Copy link
Owner

Hi @tabascoterrier !
It's very interesting topic. It's really useful if you could trigger some errors in this way :) Your idea is great, because RCPT TO command is sent very early and you can trigger any reponse on every later stage... will try to find a while to use your idea and maybe extend it a bit :) Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants