I updated my code:
1) I added the following properties:
Properties props=new Properties();
props.put(smtp,host);
props.put("mail.smtp.reportsuccess","true");
props.put("mail.smtp.sendpartial", "true");
Then written this block as directed in answer:
}catch (MessagingException mex){
Exception ex = mex;
do {
if(ex instanceof SendFailedException) {
SendFailedException sfe = (SendFailedException) ex;
Address[] vsa = sfe.getValidSentAddresses();
Address[] vua = sfe.getValidUnsentAddresses();
Address[] ia = sfe.getInvalidAddresses();
if(vsa !=null || vsa.length>0){
String validSentAddresses = vsa[0].toString();
printReport("GSWvalidSentAddresses.txt", validSentAddresses);
}
else if(vua !=null || vua.length>0){
String validUnsentAddresses = vua[0].toString();
printReport("GSWvalidUnsentAddresses.txt", validUnsentAddresses);
}
else if(ia !=null || ia.length>0){
String invalidAddresses = ia[0].toString();
printReport("GSWinvalidAddresses.txt", invalidAddresses);
}
else{}
if (ex instanceof MessagingException)
ex = ((MessagingException) ex).getNextException();
else
ex = null;
}//
} while (ex != null);
}//main catch block
}
when it ran throws 504 Gateway Time-out--------nginx
Please advise
Thanks in anticipation
Set the mail.smtp.reportsuccess session property to true. This will cause Transport.send to always throw SendFailedException. Per the documentation:
The use of the word 'chained' means you have to call MessagingException.getNextException().
Also of interest is to you is the 'mail.smtp.sendpartial' property which is also covered in the documentation.
You should also change the code to use Session.getInstance.