- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序对电子邮件收件人存在循环,其中一些收件人的地址可能不正确。当遇到不好的情况时,我希望将其报告给用户并继续循环。问题是,即使我捕获所有可能的异常,SMTPAddressFailedException 也会被 javax 捕获:
javax.mail.SendFailedException:地址无效; 嵌套异常是: 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;
}
}
最佳答案
我通过实现一个名为 sendMailToAnEntrant() 的辅助函数解决了这个问题。然后,for 循环在 try-catch 中对 sendMailToAnEntrant() 进行了一次调用。这会导致 javax 代码抛出的异常被捕获。似乎有效。
for(Entry entry : theEntries){
try {
//sendMailToAnEntrant(Concours aConcours, String aFromEmailAddress, String aSubject, String aContentTemplate, String [] aTags, Entry aEntry, Session aSession)
sendMailToAnEntrant(aConcours, mailuser, "Your JCNA Concours Entry", content_template, theTags, entry, session);
} catch (MessagingException ex) {
MasterPersonExt mp = aConcours.GetMasterPersonnelObject().GetMasterPerson(entry.GetOwnerUnique()) ;
String owneremail = mp.getEmail();
String ownername = mp.getFirstName() + " " + mp.getLastName();
String msg = "Messaging Exception in sendMailToAnEntrant() for: " + ownername + " Email: " + owneremail;
System.out.println(msg);
okDialog(msg);
aConcours.GetLogger().log(Level.INFO, msg, ex);
//Logger.getLogger(SendMailSSL.class.getName()).log(Level.SEVERE, null, ex);
continue;
}
关于java - 如何捕获嵌套的 SMTPAddressFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56350548/
我的应用程序对电子邮件收件人存在循环,其中一些收件人的地址可能不正确。当遇到不好的情况时,我希望将其报告给用户并继续循环。问题是,即使我捕获所有可能的异常,SMTPAddressFailedExcep
我正在使用 linux 服务器在 Tomcat 上运行我的应用程序,它正在发送电子邮件,但出现以下错误 通过查看此日志我无法找到问题的确切位置,有什么建议吗??? 15/12/2010 06:00:3
我正在尝试使用 Spring 生成并发送自动邮件。 尝试发送电子邮件时出现此异常: org.springframework.mail.MailSendException: Failed message
我正在尝试向用户提供的电子邮件 ID 发送电子邮件,但结果如下: org.springframework.mail.MailSendException: Failed messages: javax.
我试图从我的Grails应用程序中使用javamail发送邮件(通过服务)。 所使用的发件人和收件人地址均具有组织域名。 通过命令行作为groovy脚本(在同一服务器上)运行时,相同的代码可以按预期工
我有一个 Spring 4.1.1 Web 应用程序,用户可以在其中设置一些计划任务。当这些任务完成后,管理员将收到一封使用 SMTP 方法发送的自动电子邮件。 对于电子邮件,我使用 jar:java
我正在尝试从 Java 发送邮件。如果我将邮件发送到同一个 SMTP,它工作正常。如果我将邮件发送到 Gmail、Yahoo 等外部 SMTP 方式,它会显示如下错误, [com.sun.mail.s
我正在使用以下代码但收到错误消息 -运行: javax.mail.SendFailedException: Invalid Addresses; nested exception is:
我遇到一些未知类型的错误,我发送邮件的代码如下 String mail_smtp_host=directoryPath("mail_smtp_host"); final String
我正在尝试使用 JavaMail 发送邮件。 properties.put("mail.smtp.host", "smtp.estudiantes.ve"); properties.put("mail
我是一名优秀的程序员,十分优秀!