-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Testing SMTP Server Error Responses #402
Comments
Previously a "chaos monkey" feature was requested (see #110, #144 & #268) to return SMTP errors at random. That proposal was rejected at the time because it was impossible to implement (properly) due to the fact that Mailpit was reliant a third party library for SMTP. Whilst Mailpit is still using a version of that library, it is now within the Mailpit codebase meaning it is now technically possible. What you are asking for however is something different, so to help me understand your requirements:
The example given previously was MailHog's Jim feature which is what many/all of these previous requests were based on, and which may help provide some suggestions and ideas for this discussion. Just to be clear, I'm not saying (yet) whether I will add this option, I'm just a lot more open to it now because it is now possible, it just needs to be implemented properly which takes a solid understanding of the requirements, and of course planning. It is also worth mentioning that I am having shoulder surgery in 2 days, so if I am to add this option it would likely only be in January or February next year, which gives me plenty of time to consider the options before then. |
Thank you very much for taking the time to answer my question.
Especially for me need 100% chance of failure.
Need specific type of failure. For example, for development backend reaction on 451 error.
Maybe. My Backend connect to SMTP, send E-mail and disconnect.
Nothing else comes to mind. |
Just an idea on how to implement this: |
Now that's an interesting approach, thanks for the idea @ThomasLandauer 👍 Edit: After some thought and as nice as this idea sounds, it is very limited in that the email would need to have already been processed in order to process the addresses, meaning the only failure one could trigger this way would be after a successful transaction. |
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.
I have just released v1.22.0 which adds new "Chaos" functionality (see release notes and links for documentation). The configuration is fairly flexible to allow you to set the error code and probability (which determines whether you want it to trigger never, randomly, or always), and can be set / changed via CLI flags (or environment variables), and if enabled, can be modified via both the web UI and API. Please let me know how it works for you? Thanks. |
I've read those issues where people are requesting that chaos feature, but - to be honest - I don't understand their use case, (i.e. how adding unpredictability helps ;-) Anyway, my use case is: I have a test suite that I run before deploying. The test suite contains a test for a successful connection to my mailserver (represented by Mailpit), and one test for an unsuccessful connection. The current implementation (if I understand it right) would require me to create a separate test suite for the unsuccessful test, and restart Mailpit when switching between theses test suites. This feels even clumsier than the hack I currently have (see #405 (comment)) So what I'd like to have would be a way to "request" an error from within the test. So my idea would be to either hard-code some "special" email address ([email protected]) or subject ("Please answer with error") or any other part of the email itself (X-Mailpit-Give-Error: Yes). Or add some API call (that can be triggered with cURL) which causes an error in the next SMTP session. |
Thanks for the feedback @ThomasLandauer. Chaos (engineering) revolves around handling unpredictability (ie: failures at random), which is different to you r case where you want to predict the failure. Predictability however can be achieved with the same functionality by setting the failure trigger to 100(%) probability, guaranteeing it will fail. If I understand correctly, your test suite spins up an instance of Mailpit when it runs the test. You do not need to spin up a separate instance of Mailpit or do a completely separate test to get a failure, you just need to:
This matches your last point exactly, so either I'm confused, or maybe the instructions are not clear? |
Thanks, this works! :-) Some suggestions (somewhat unordered - sorry):
|
Great!
It's currently described & linked to from the project's README, Mailpit's home page, the features page, the configuration page , and the runtime options pages, so I really don't think it can be any more prominent than that, especially considering it's an advanced option which most users will never need or use. ;-)
Whilst I get your point, the online API documentation differs somewhat from the bundled (in Mailpit itself) API documentation which does - there are actually clear curl examples in the bundled documentation. The reason for the difference is that the website cannot know what IP your Mailpit instance is actually using, it's webroot, or whether it's even running, and I'm concerned that the average user will start posting Github issues because "it's not working" for them. I will make the information about the bundled API documentation clearer on the website and explain this.
Ironically, I had it as
Quite possibly - I don't format the HTTP response manually, it's using Go's built-in JSON encoding to turn a struct (of the current config) into a JSON string. On that note, JSON should never be validated as a 1:1 string, as it it is prone to formatting differences (eg: "pretty"), and the fact that the order of keys can differ per implementation (Go will set them alphabetically, but PHP for instance won't). A JSON string should be converted to JSON and then parsed, and a JSON string with or without trailing lines is valid. |
Sometimes during development you need to write logic for error responses from the SMTP server.
Can you add this feature to Mailpit Test Server?
There could be some startup keys that make Mailpit respond with an error.
For example, 451.
The text was updated successfully, but these errors were encountered: