]> source.dussan.org Git - gitblit.git/commitdiff
Improve logging when sending email fails. 1144/head merged-logSendFailedException
authorFlorian Zschocke <florian.zschocke@cycos.com>
Tue, 18 Nov 2014 22:53:33 +0000 (23:53 +0100)
committerFlorian Zschocke <florian.zschocke@cycos.com>
Thu, 27 Oct 2016 21:52:13 +0000 (23:52 +0200)
src/main/java/com/gitblit/service/MailService.java

index ec3a84ca186c933f72d210f637048e4c0b10d899..58acc9c0653002f6ede473397d02f9754d86b749 100644 (file)
@@ -17,6 +17,7 @@ package com.gitblit.service;
 \r
 import java.io.File;\r
 import java.util.ArrayList;\r
+import java.util.Arrays;\r
 import java.util.Date;\r
 import java.util.List;\r
 import java.util.Properties;\r
@@ -31,6 +32,7 @@ import javax.mail.Authenticator;
 import javax.mail.Message;\r
 import javax.mail.MessagingException;\r
 import javax.mail.PasswordAuthentication;\r
+import javax.mail.SendFailedException;\r
 import javax.mail.Session;\r
 import javax.mail.Transport;\r
 import javax.mail.internet.InternetAddress;\r
@@ -272,9 +274,22 @@ public class MailService implements Runnable {
                                while ((message = queue.poll()) != null) {\r
                                        try {\r
                                                if (settings.getBoolean(Keys.mail.debug, false)) {\r
-                                                       logger.info("send: " + StringUtils.trimString(message.getSubject(), 60));\r
+                                                       logger.info("send: '" + StringUtils.trimString(message.getSubject(), 60)\r
+                                                                           + "' to:" + StringUtils.trimString(Arrays.toString(message.getAllRecipients()), 300));\r
                                                }\r
                                                Transport.send(message);\r
+                                       } catch (SendFailedException sfe) {\r
+                                               if (settings.getBoolean(Keys.mail.debug, false)) {\r
+                                                       logger.error("Failed to send message: {}", sfe.getMessage());\r
+                                                       logger.info("   Invalid addresses: {}", Arrays.toString(sfe.getInvalidAddresses()));\r
+                                                       logger.info("   Valid sent addresses: {}", Arrays.toString(sfe.getValidSentAddresses()));\r
+                                                       logger.info("   Valid unset addresses: {}", Arrays.toString(sfe.getValidUnsentAddresses()));\r
+                                                       logger.info("", sfe);\r
+                                               }\r
+                                               else {\r
+                                                       logger.error("Failed to send message: {}", sfe.getMessage(), sfe.getNextException());\r
+                                               }\r
+                                               failures.add(message);\r
                                        } catch (Throwable e) {\r
                                                logger.error("Failed to send message", e);\r
                                                failures.add(message);\r