We are using Java Mail 1.5 API to send mails. The SMTP host we are using for development, does not have any suppression list, hence, if any emails being invalid, like "xyz@xyz.com" will be sent and though its hard bounced back, we get it in the getInvalidAddresses() of exception,
but if we try a prod SMTP server, which has a suppression list, the same email "xyz@xyz.com" causes the other emails to NOT being sent, if they are part of the same TO list, like "valid@domain.com; xyz@xyz.com", our expectation is at-least "valid@domain.com" should get the email, but even that is not sent and getInvalidAddresses() is null
com.sun.mail.smtp.SMTPAddressFailedException: 254 4.7.1 - xyz@xyz.com is suppressed for sender smtp.xxx.xxx
public class SendMail {
public static void main(String[] args) {
final String username = "username@domain.com";
final String password = "xxxxxxxxxxxx";
Properties prop = new Properties();
prop.put("mail.smtp.host", "mysmtp.domain.com");
prop.put("mail.smtp.port", "25");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.sendpartial", "true");
prop.put("mail.smtp.socketFactory.port", "25");
prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session = Session.getInstance(prop,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@domain.com"));
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse("valid@domain.com, xyz@xyz.com")
);
message.setSubject("Test Mail");
message.setText("Test Mail");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
How can we handle suppression list errors in Java Mail API?