【发布时间】:2015-04-13 05:22:35
【问题描述】:
我正在开发一个在 Liferay 中发送邮件的代码... 这里的问题是我想发送一条错误消息
portletRequest.setAttribute("mailError", new String("smobile.error.mail"))
当邮件服务器(SMTP)关闭时..
这里是源代码。
try {
MailMessage mailMessage = new MailMessage();
mailMessage.setFrom(new InternetAddress(fromEmail));
mailMessage.setSubject(subjectTemplate);
mailMessage.setBody(bodyTemplate);
mailMessage.setHTMLFormat(true);
mailMessage.setTo(new InternetAddress(toEmail));
// Send Mail
MailServiceUtil.sendEmail(mailMessage);
_log.info("Confirmation email sent with success!");
} catch(MessagingException me) {
if (me.getNextException() instanceof SocketException) {
_log.warn("EMAIL ENGINE ERROR");
portletRequest.setAttribute("mailError", new String("smobile.error.mail"));
}
throw new MailEngineException(me);
}
非常感谢。
【问题讨论】:
标签: java exception-handling smtp jakarta-mail liferay-6