"invalid addresses" exception too broad
I recently got lots of error messages from jakarta/angus mail: Invalid addresses but on further inspection (most of) the addresses were correct and valid. I had to dig through a lot of exception causes until I got to the real issue(s). Those were for example:
'Invalid Addresses' (3x caused by later): 471 4.7.1 <[email protected]>: The limits for your account are exceeded. Please try again later.
'Invalid Addresses' (3x caused by later): 550 5.4.4 Unable to relay
'Invalid Addresses' (3x caused by later): 500 5.0.0 Syntax error, command unrecognized
'Invalid Addresses' (3x caused by later): 555-5.5.2 Syntax error, cannot decode response. For more information, go to 555-5.5.2 https://support.google.com/a/answer/3221692 and review RFC 5321 555 5.5.2 specifications.
'Invalid Addresses' (3x caused by later): 554 5.7.1 Client host rejected: Access denied
It seems that "invalid addresses" is some kind of default or fallback error message, which is however incorrect in certain (many?) cases.
Would it be possible to use a different error message like Error sending mail in case no clear or an unknown error code is used.
Ideally (optionally) the cause from the server would be great:
"Error sending email. The server reply was: '471 4.7.1 The limits for your account are exceeded.' "
That log looks like the debug log. What is the full Java stacktrace with exception names?
It is not a debug log since a real exception during mail sending is thrown...
- skipped unrelated parts of the stack trace -
Caused by: javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 471 4.7.1 <[email protected]>: Recipient address rejected: Rejected: The limits for your account are exceeded. Please try again later.
at [email protected]//com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:2064)
at [email protected]//com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1286)
at deployment.ear//...
... 170 more
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 471 4.7.1 <[email protected]>: Recipient address rejected: Rejected: The limits for your account are exceeded. Please try again later.
at [email protected]//com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1964)
... 172 more
I know it is still the javax version of mail since we just recently upgraded to angus mail (but not productive yet)
Ok that helps. The source of the behavior is in the SMTPSendFailedException API docs:
This exception is thrown when the message cannot be sent. This exception will usually appear first in a chained list of exceptions, followed by SMTPAddressFailedExceptions and/or SMTPAddressSucceededExceptions, * one per address. This exception corresponds to one of the SMTP commands used to send a message, such as the MAIL, DATA, and "end of data" commands, but not including the RCPT command.
We just need to dig into the logic to see if it was incorrectly was added to invalid list instead of the unsent list.