From: Florian Zschocke Date: Tue, 18 Nov 2014 22:53:33 +0000 (+0100) Subject: Improve logging when sending email fails. X-Git-Tag: merged-logSendFailedException X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1144%2Fhead;p=gitblit.git Improve logging when sending email fails. --- diff --git a/src/main/java/com/gitblit/service/MailService.java b/src/main/java/com/gitblit/service/MailService.java index ec3a84ca..58acc9c0 100644 --- a/src/main/java/com/gitblit/service/MailService.java +++ b/src/main/java/com/gitblit/service/MailService.java @@ -17,6 +17,7 @@ package com.gitblit.service; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Properties; @@ -31,6 +32,7 @@ import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; +import javax.mail.SendFailedException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; @@ -272,9 +274,22 @@ public class MailService implements Runnable { while ((message = queue.poll()) != null) { try { if (settings.getBoolean(Keys.mail.debug, false)) { - logger.info("send: " + StringUtils.trimString(message.getSubject(), 60)); + logger.info("send: '" + StringUtils.trimString(message.getSubject(), 60) + + "' to:" + StringUtils.trimString(Arrays.toString(message.getAllRecipients()), 300)); } Transport.send(message); + } catch (SendFailedException sfe) { + if (settings.getBoolean(Keys.mail.debug, false)) { + logger.error("Failed to send message: {}", sfe.getMessage()); + logger.info(" Invalid addresses: {}", Arrays.toString(sfe.getInvalidAddresses())); + logger.info(" Valid sent addresses: {}", Arrays.toString(sfe.getValidSentAddresses())); + logger.info(" Valid unset addresses: {}", Arrays.toString(sfe.getValidUnsentAddresses())); + logger.info("", sfe); + } + else { + logger.error("Failed to send message: {}", sfe.getMessage(), sfe.getNextException()); + } + failures.add(message); } catch (Throwable e) { logger.error("Failed to send message", e); failures.add(message);