瀏覽代碼

before send mail, check whether no receivers && cc receivers.

to avoid exception javax.mail.SendFailedException: No recipient
addresses. Especially from SQL Task
Baoqi 6 年之前
父節點
當前提交
2714cb1e6d
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java

+ 7 - 2
escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java

@@ -102,11 +102,16 @@ public class MailUtils {
      */
     public static Map<String,Object> sendMails(Collection<String> receivers, Collection<String> receiversCc, String title, String content, ShowType showType) {
         Map<String,Object> 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();