Мое приложение имеет петлю для получателей электронной почты, некоторые из которых могут иметь неправильные адреса.Когда встречается плохой, я бы хотел, чтобы он сообщил пользователю и цикл продолжился.Проблема в том, что, хотя я перехватываю все возможные исключения, вместо этого создается исключение SMTPAddressFailedException с помощью javax:
javax.mail.SendFailedException: Invalid Addresses;вложенное исключение: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1: адрес получателя отклонен: пользователь неизвестен в таблице виртуальных почтовых ящиков
, а остальные получатели пропускаются.Какой правильный способ справиться с этим?
Вот код:
List<Entry> theEntries = theConcours.GetEntriesList();
for(Entry entry : theEntries){
MasterPersonExt mp = aConcours.GetMasterPersonnelObject().GetMasterPerson(entry.GetOwnerUnique()) ;
String owneremail = mp.getEmail();
String ownername = mp.getFirstName() + " " + mp.getLastName();
curOwnerUniqueName = mp.getUniqueName();
System.out.println("Processing " + mp.getUniqueName() + " email: " + owneremail);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(mailuser));
System.out.println("From set while processing " + curOwnerUniqueName);
} catch (AddressException ex) {
String msg = "AddressException for: " + mailuser + " while processing " + curOwnerUniqueName;
//Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
okDialog(msg);
aConcours.GetLogger().log(Level.INFO, msg, ex);
continue;
} catch (MessagingException ex) {
// Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
String msg = "MessagingException for: " + mailuser + " while processing " + curOwnerUniqueName;
//Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
okDialog(msg);
aConcours.GetLogger().log(Level.INFO, msg, ex);
continue;
}
try {
message.setSubject("Your JCNA Concours Entry");
} catch (MessagingException ex) {
// Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
String msg = "MessagingException setting Subject while processing " + curOwnerUniqueName ;
//Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
okDialog(msg);
aConcours.GetLogger().log(Level.INFO, msg, ex);
continue;
}
InternetAddress ownerInternetAddr;
try {
ownerInternetAddr = new InternetAddress(owneremail);
} catch (AddressException ex) {
String msg = "Bad judge eMail address for " + curOwnerUniqueName + " \"" + mp.getEmail() + "\"";
okDialog(msg);
Logger.getLogger(SendMailSSL.class.getName()).log(Level.INFO, msg, ex);
continue;
}
try {
///
message.addRecipient(Message.RecipientType.TO, ownerInternetAddr);
} catch (MessagingException ex) {
// Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
String msg = "MessagingException setting TO while processing " + curOwnerUniqueName + " \"" + mp.getEmail() + "\"";
okDialog(msg);
Logger.getLogger(SendMailSSL.class.getName()).log(Level.INFO, msg, ex);
continue;
}
String ownerFirst = entry.GetOwnerFirst();
String entryplacard = "http://www.concoursbuilder.us/manual-uploads/" + theConcours.GetHostClub() + "/" + concoursName + "/Placards/" + entry.GetOwnerLast() + "_" + entry.GetUniqueDescription() + "-Placard.pdf";
String jagModel = entry.GetModel();
String[] theVals = {ownerFirst, jagModel, concoursName, judgingStarts, lunchTime,
awardsTime, concoursChairFirstLastName, concoursChairEmail, entryplacard, schedbyclass};
messageContent = replaceTagsWithValues(content_template, theTags, theVals);
try {
message.setContent(messageContent, "text/html; charset=utf-8");
} catch (MessagingException ex) {
//Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
String msg = "MessagingException setting Content while processing " + curOwnerUniqueName + " \"" + mp.getEmail() + "\"";
okDialog(msg);
Logger.getLogger(SendMailSSL.class.getName()).log(Level.INFO, msg, ex);
continue;
}
//send the message
try {
Transport.send(message);
System.out.println("message sent successfully...");
} catch (SMTPAddressFailedException ex){
String msg = "SMTPAddressFailedException while processing Owner " + ownername + " email address " + owneremail + " is invalid.";
System.out.println(msg);
okDialog(msg);
aConcours.GetLogger().log(Level.INFO, msg, ex);
continue;
} catch (MessagingException ex) {
// Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
String msg = "MessagingException while processing Owner " + ownername + " email address " + owneremail;
System.out.println(msg);
okDialog(msg);
aConcours.GetLogger().log(Level.INFO, msg, ex);
continue;
}
}