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

Enable using RSET after transaction failures in deliver/2 #264

Merged
merged 1 commit into from
Sep 30, 2021

Conversation

juhlig
Copy link
Contributor

@juhlig juhlig commented Jun 15, 2021

The current client implementation of gen_smtp_client:deliver/2 always quits the connection to the server when it receives a failure reply in answer to MAIL FROM, RCPT TO, DATA, or the mail body.
Instead, RSET could be used to reset (ie cancel) the transaction and keep the connection open.

This PR introduces the option on_transaction_error which can be used in a gen_smtp_client:open/1 call. Possible values are quit (the default, resulting in the current behavior) and reset.

When reset is given for this option, the client will try to issue a RSET command after receiving a 4xx or 5xx response code in answer to MAIL FROM, RCPT TO or DATA (other unexpected replies will cause a quit), and leave the socket connected if the server replies with 250 to the RSET command (otherwise it will quit).
If it receives a 4xx or 5xx response after sending the mail body, the transaction is already finished and no RSET is needed, but the socket is kept open. Any other unexpected replies will cause a quit.

@seriyps
Copy link
Collaborator

seriyps commented Sep 20, 2021

Hi, thanks for your PR and sorry for not reviewing it for so long. I think it's a great idea, but I think it would be really nice if you will add a couple of tests where you set this option to reset and assert that the behaviour is different.

@juhlig
Copy link
Contributor Author

juhlig commented Sep 22, 2021

Hi, thanks for your PR and sorry for not reviewing it for so long.

No problem :)

I think it's a great idea, but I think it would be really nice if you will add a couple of tests where you set this option to reset and assert that the behaviour is different.

I added two tests, one for RSET, one for QUIT. They are a bit more complicated than the others, the feature can only be tested fully with deliver to see that the connection stays open (or gets closed), not with send which implicitly closes the connection.

@mworrell mworrell merged commit a11f0f8 into gen-smtp:master Sep 30, 2021
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.

3 participants