From 4218f97ed40240c28d57ae8cb4f9e521d8a65ad3 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Tue, 18 Nov 2014 23:53:33 +0100 Subject: [PATCH] Improve logging when sending email fails. --- .../java/com/gitblit/service/MailService.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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); -- 2.39.5