From 2714cb1e6d408fd7f108733507ccef3ffc16af22 Mon Sep 17 00:00:00 2001 From: Baoqi Date: Thu, 11 Apr 2019 16:55:34 +0800 Subject: [PATCH 1/2] before send mail, check whether no receivers && cc receivers. to avoid exception javax.mail.SendFailedException: No recipient addresses. Especially from SQL Task --- .../main/java/cn/escheduler/alert/utils/MailUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java b/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java index 42fbebd2f2..3675d4c919 100644 --- a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java +++ b/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java @@ -102,11 +102,16 @@ public class MailUtils { */ public static Map sendMails(Collection receivers, Collection receiversCc, String title, String content, ShowType showType) { Map retMap = new HashMap<>(); - retMap.put(Constants.STATUS, false); - receivers.removeIf((from) -> (StringUtils.isEmpty(from))); + // if there is no receivers && no receiversCc, no need to process + if (CollectionUtils.isEmpty(receivers) && CollectionUtils.isEmpty(receiversCc)) { + retMap.put(Constants.STATUS, true); + return retMap; + } + + retMap.put(Constants.STATUS, false); if (showType == ShowType.TABLE || showType == ShowType.TEXT){ // send email HtmlEmail email = new HtmlEmail(); From 4fbd9380dee44658f5c554d9839ffd8f959eeda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=94=E5=8D=A0=E5=8D=AB?= <825193156@qq.com> Date: Thu, 11 Apr 2019 17:19:42 +0800 Subject: [PATCH 2/2] Update MailUtils.java if there is no receivers && no receiversCc, no need to process --- .../main/java/cn/escheduler/alert/utils/MailUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java b/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java index 3675d4c919..0e514ffee6 100644 --- a/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java +++ b/escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java @@ -102,16 +102,15 @@ public class MailUtils { */ public static Map sendMails(Collection receivers, Collection receiversCc, String title, String content, ShowType showType) { Map retMap = new HashMap<>(); - - receivers.removeIf((from) -> (StringUtils.isEmpty(from))); - + retMap.put(Constants.STATUS, false); + // if there is no receivers && no receiversCc, no need to process if (CollectionUtils.isEmpty(receivers) && CollectionUtils.isEmpty(receiversCc)) { - retMap.put(Constants.STATUS, true); return retMap; } - retMap.put(Constants.STATUS, false); + receivers.removeIf((from) -> (StringUtils.isEmpty(from))); + if (showType == ShowType.TABLE || showType == ShowType.TEXT){ // send email HtmlEmail email = new HtmlEmail();