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

WIP: Answering with SMTP error code, for testing #405

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ThomasLandauer
Copy link
Contributor

Closes #402

My knowledge of Go is (in your syntax): nil
But I'm sure you get the idea :-)

Based on your comment at #402 (comment)

the email would need to have already been processed in order to process the addresses

I'm guessing that maybe you aren't using the address given at MAIL FROM at all. If this is indeed the case, then it certainly would be easy to capture the contents of your mailFromREs first parentheses into some variable.

Closes axllent#402

My knowledge of Go is (in your syntax): `nil`
But I'm sure you get the idea :-)

Based on your comment at axllent#402 (comment)
> the email would need to have already been processed in order to process the addresses

I'm *guessing* that maybe you aren't using the address given at `MAIL FROM` at all. If this is indeed the case, then it certainly would be easy to capture the contents of your `mailFromRE`s first parentheses into some variable.
@axllent
Copy link
Owner

axllent commented Dec 12, 2024

the email would need to have already been processed in order to process the addresses

I'm guessing that maybe you aren't using the address given at MAIL FROM at all. If this is indeed the case, then it certainly would be easy to capture the contents of your mailFromREs first parentheses into some variable.

Not quite (I worded that poorly). What I am meaning is that in order to parse the MAIL FROM data in the email being received, the SMTP transaction would have already had to have passed several steps (eg: EHLO, AUTH *, STARTTLS etc). This would mean that this approach would only work from the MAIL FROM command onwards, which may be too limited for testing (depending on what is being tested).

It also means there is always a 100% failure guarantee, whereas some testers may want a random failure to test things like retrying a send based on a temporary failure. By using a constant in a mail address like this, a retry would always trigger the same response because the same address is parsed again and again.

Please don't get me wrong - I like your approach because it is dynamic and does not introduce new CLI & environment variables, but it may be too limited to address "the bigger requirement".

I just need time to think this through properly and consider all the options and requirements 👍

@ThomasLandauer
Copy link
Contributor Author

Foreword: I came up with the idea of _code_500_after_mail_from because it's easy to implement (just some ifs here and there), not because I think there is a real need for this flexibility ;-)

I think that thoroughly testing the entire SMTP session with Mailpit just doesn't make any sense, cause: In production, the app (which uses an SMTP library in 99%, not some self-written code) needs to talk to the real MTA. So testing if this SMTP library plays together nicely with Mailpit is quite useless, isn't it?

IMO, the real use-case is that people want to ensure how their app reacts if the MTA returns 500. In my case, I'm currently generating the error in my app with something like that:

if (environment == 'test' and 'subject' == 'Please give me an error') {
    return false;
} else {
    // contact the MTA to actually send the mail
}

But since this is ugly, it would be nice to have a way to make Mailpit simulate such an error.

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

Successfully merging this pull request may close these issues.

Testing SMTP Server Error Responses
2 participants