TeslaCN commented on a change in pull request #1550:
URL: 
https://github.com/apache/shardingsphere-elasticjob/pull/1550#discussion_r503620141



##########
File path: 
elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
##########
@@ -95,28 +96,35 @@ private String createErrorContext(final String jobName, 
final Throwable cause) {
         return String.format("Job '%s' exception occur in job processing, 
caused by %s", jobName, writer.toString());
     }
     
-    private Message createMessage(final String content) throws 
MessagingException {
-        MimeMessage result = new MimeMessage(session);
-        result.setFrom(new InternetAddress(config.getFrom()));
-        result.setSubject(config.getSubject());
+    private Message createMessage(final String content, final 
EmailConfiguration emailConfiguration) throws MessagingException {
+        MimeMessage result = new 
MimeMessage(createSession(emailConfiguration));
+        result.setFrom(new InternetAddress(emailConfiguration.getFrom()));
+        result.setSubject(emailConfiguration.getSubject());
         result.setSentDate(new Date());
         Multipart multipart = new MimeMultipart();
         BodyPart mailBody = new MimeBodyPart();
         mailBody.setContent(content, "text/html; charset=utf-8");
         multipart.addBodyPart(mailBody);
         result.setContent(multipart);
-        if (StringUtils.isNotBlank(config.getTo())) {
-            result.addRecipient(Message.RecipientType.TO, new 
InternetAddress(config.getTo()));
+        String to = emailConfiguration.getTo();
+        if (StringUtils.isNotBlank(to)) {
+            String[] tos = to.split(",");
+            for (String t : tos) {
+                result.addRecipient(Message.RecipientType.TO, new 
InternetAddress(t));
+            }
+        }
+        if (StringUtils.isNotBlank(emailConfiguration.getCc())) {
+            result.addRecipient(Message.RecipientType.CC, new 
InternetAddress(emailConfiguration.getCc()));
         }
-        if (StringUtils.isNotBlank(config.getCc())) {
-            result.addRecipient(Message.RecipientType.CC, new 
InternetAddress(config.getCc()));
+        if (StringUtils.isNotBlank(emailConfiguration.getBcc())) {
+            result.addRecipient(Message.RecipientType.BCC, new 
InternetAddress(emailConfiguration.getBcc()));
         }
         result.saveChanges();
         return result;
     }
     
-    private void sendMessage(final Message message) throws MessagingException {
-        try (Transport transport = session.getTransport()) {
+    private void sendMessage(final Message message, final EmailConfiguration 
emailConfiguration) throws MessagingException {
+        try (Transport transport = 
createSession(emailConfiguration).getTransport()) {

Review comment:
       Consider using `Optional.ofNullable(session).orElseGet(() -> 
createSession(emailConfiguration))`




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to