SbloodyS commented on code in PR #16529:
URL: 
https://github.com/apache/dolphinscheduler/pull/16529#discussion_r1732473669


##########
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java:
##########
@@ -378,13 +382,42 @@ private AlertResult getStringObjectMap(String title, 
String content, AlertResult
 
         // send
         email.setDebug(true);
-        email.send();
-
+        email.buildMimeMessage();
+        sendMail(email.getMimeMessage(), email.getMailSession());
         alertResult.setSuccess(true);
 
         return alertResult;
     }
 
+    /**
+     * send mail with validAddresses retry
+     *
+     * @param mimeMessage the message
+     * @param session connectSession
+     */
+    private void sendMail(MimeMessage mimeMessage, Session session) throws 
MessagingException, AlertEmailException {
+        Transport transport = session.getTransport(new SMTPProvider());
+        transport.addTransportListener(new TransportAdapter() {
+            @Override
+            public void messageNotDelivered(TransportEvent event) {
+                Address[] validUnsentAddresses = 
event.getValidUnsentAddresses();
+                if (validUnsentAddresses == null || 
validUnsentAddresses.length < 1) {
+                    return;
+                }
+                try {
+                    transport.sendMessage(mimeMessage, validUnsentAddresses);
+                } catch (MessagingException e) {
+                    log.error("send mail with validAddresses failed:{}", 
e.getMessage());
+                    throw new AlertEmailException("send mail with 
validAddresses failed", e);

Review Comment:
   We don't need to throw exception here.



##########
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java:
##########
@@ -378,13 +382,42 @@ private AlertResult getStringObjectMap(String title, 
String content, AlertResult
 
         // send
         email.setDebug(true);
-        email.send();
-
+        email.buildMimeMessage();
+        sendMail(email.getMimeMessage(), email.getMailSession());
         alertResult.setSuccess(true);
 
         return alertResult;
     }
 
+    /**
+     * send mail with validAddresses retry
+     *
+     * @param mimeMessage the message
+     * @param session connectSession
+     */
+    private void sendMail(MimeMessage mimeMessage, Session session) throws 
MessagingException, AlertEmailException {
+        Transport transport = session.getTransport(new SMTPProvider());
+        transport.addTransportListener(new TransportAdapter() {
+            @Override
+            public void messageNotDelivered(TransportEvent event) {
+                Address[] validUnsentAddresses = 
event.getValidUnsentAddresses();
+                if (validUnsentAddresses == null || 
validUnsentAddresses.length < 1) {
+                    return;
+                }
+                try {
+                    transport.sendMessage(mimeMessage, validUnsentAddresses);
+                } catch (MessagingException e) {
+                    log.error("send mail with validAddresses failed:{}", 
e.getMessage());

Review Comment:
   ```suggestion
                       log.error("send mail with validAddresses failed: {}, 
reason:", validUnsentAddresses, e);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to