【问题标题】:SMTP Exception handlingSMTP 异常处理
【发布时间】: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


    【解决方案1】:

    此 JavaMail 常见问题解答条目可能会有所帮助:

    我无法从您的问题中看出您期望您没有发现什么样的错误。而且我不知道你为什么只在 MessagingException 中寻找嵌入的 SocketExceptions。

    【讨论】:

    • 感谢您的回答。我的目标是捕获 SMTP 服务器异常......实际上,我有这个错误:“无法发送邮件”。答案是我建议用 ext-plugin 覆盖 MailEngine 类(它在 util-java 中)以不同方式处理异常,然后直接从插件中使用它,而不是 MailServiceUtil,它只将所有内容推送到消息总线。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多