Skip to content

Commit

Permalink
Merge pull request #825 from ayeshLK/email-dev
Browse files Browse the repository at this point in the history
[Master] Improve send failed exception with invalid addresses
  • Loading branch information
ayeshLK authored Aug 7, 2024
2 parents 07823b1 + 557d5bb commit 32b99b1
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Properties;
import java.util.stream.Collectors;

import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;

Expand Down Expand Up @@ -91,6 +95,12 @@ public static Object sendMessage(BObject clientConnector, BMap<BString, Object>
(Session) clientConnector.getNativeData(EmailConstants.PROPS_SESSION),
(String) clientConnector.getNativeData(EmailConstants.PROPS_USERNAME.getValue()), message));
return null;
} catch (SendFailedException e) {
String invalidAddresses = Arrays.stream(e.getInvalidAddresses())
.map((Address::toString))
.collect(Collectors.joining(","));
return CommonUtil.getBallerinaError(EmailConstants.ERROR,
"Error while sending the message to SMTP server : " + e.getMessage() + " " + invalidAddresses);
} catch (MessagingException | IOException e) {
log.debug("Error while sending the message to SMTP server : ", e);
return CommonUtil.getBallerinaError(EmailConstants.ERROR, e.getMessage());
Expand Down

0 comments on commit 32b99b1

Please sign in to comment.