1

I am attempting to send bulk email without create new session for every mail recipient because of performance considering.

But i am facing one problem in this. if one of the recipient is invalid, then job could not send mail to other recipients. In this scenario i need to send mail to other recipients

Below is my code snippet, Kindly provide any suggestion for this problem.

Session session = Session.getInstance(props, null);
Message message = new MimeMessage(session);

message.setFrom(new InternetAddress(mailFrom));
message.setSubject(subject);

message.setContent(messageStr, "text/html");

if (mailTo != null) {
    for (int i = 0; i < mailTo.length; i++) {
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(mailTo[i]));
    }
}

Transport.send(message);
9
  • 1
    validate the email addresses? Commented Feb 20, 2017 at 6:37
  • In worst case scenario, if any of the recipient is failed. then job is not sending mail to anyone. Commented Feb 20, 2017 at 6:39
  • so why don't you validate the email addresses? Commented Feb 20, 2017 at 6:40
  • Validation is OK.. i am thinking some other cases if failed. Commented Feb 20, 2017 at 6:41
  • 1
    @Siva use thread for that create separate thread for each time you while you sending mail and use try catch that it. Commented Feb 20, 2017 at 7:30

1 Answer 1

1

Set the Session property mail.smtp.sendpartial to true.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.