Question

I am currently getting SendFailedException because my sendmail instance has some email addresses blacklisted (to filter out all emails to non-developers during testing). But SendFailedException could also indicate a failure to connect to the SMTP server or something else. When this exception occurs because the email is blacklisted, I need to ignore the message and continue, but any other exception should be allowed to propagate out of my method. When I look at the JavaMail API, it appears that SendFailedException is the lowest level of exception I can get (the last one in the javax.mail package). What I really need is is the underlying SMTPSendFailedException, but that is in the com.sun.mail package, and, as far as I understand, that means it is implementation specific and should not be used. However, that class actually has a getReturnCode() method that could be used to differentiate between SendFailedExceptions. Is there a better way to do this? Is it safe to use com.sun.mail classes? Any suggestions?

Was it helpful?

Solution

You can use the com.sun.mail classes that are described in the javadocs. Unlike the standard javax.mail classes, which we try very hard to keep stable and compatible, there's a small chance that the com.sun.mail classes will evolve incompatibly in future releases. We understand that many people use these classes, so we would not make such changes lightly, but if necessary to improve the JavaMail implementation or to support new standard API classes, they might change.

Note that there are also lots of com.sun.mail classes that are not described in the javadocs. Use of those is much higher risk; they're much more likely to change incompatibly in even minor releases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top