vert-x3 / vertx-mail-client

Apache License 2.0
34 stars 33 forks source link

Dedicated exception for "Recipient address not accepted" (or some other "stable" way to detect this) #168

Closed famod closed 2 years ago

famod commented 2 years ago

Describe the feature

In case of an invalid recipient address, vertx-mail-client currently just throws something like:

Since NoStackTraceThrowable is generic, an application that has to react to this specifically will need to parse the execption message, e.g. for "Recipient address rejected". Such a string can change without further notice or detection, making this a fragile solution.

It would be helpful if an explicit exception would be thrown for those cases.

Use cases

Detection of invalid email addresses to e.g. notify someone or to display a specific error message in UI.

gaol commented 2 years ago

Thank you for the report. :)

The reply code has defined meanings by the specification, and if the SMTP server supports enhanced status code, there are sub codes defined as well in https://datatracker.ietf.org/doc/html/rfc3463#section-2.

I would like to introduce an explicit exception with the reply code and enhanced status code(if applicable) for all transient(4xx)/permanent(5xx) failures. Please let me know if this cannot fulfill your needs. :)

famod commented 2 years ago

@gaol Sorry for the late feedback!

I would like to introduce an explicit exception with the reply code and enhanced status code(if applicable) for all transient(4xx)/permanent(5xx) failures.

Ideally, a client should not need to interpret specific numbers, but should instead receive something like RecipientAddressNotAcceptedException. If that's what you meant then I'm fine! :smile

I'll try to have a look at the PR.

gaol commented 2 years ago

@famod np :)

Ideally, a client should not need to interpret specific numbers, but should instead receive something like RecipientAddressNotAcceptedException. If that's what you meant then I'm fine! :smile

Actually no, SMTP specifies many reply codes on failures, and some SMTP servers may extend it, it is not feasible to distinguish them all and throw different exceptions accordingly in this client IMO.

What I want to do is a way to know the failure code(should be stable approach), and with enhanced code support(not yet), we can know what categories the failure falls to, like: Address, Mailbox, Mail system, etc. Applications can decide what to do according to the failure category, something like RecipientAddressNotAcceptedException is too specific IMO.