Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem Sending mails in a loop using JavaMail API

843830Oct 14 2002 — edited Jan 23 2003
Hello All,
I am sending emails in a loop(one after the other) using JavaMail API,but the problem is, if the first two,three email addresses in the loop are Valid it sends the Email Properly, but if the Fourth or so is Invalid Address it throws an Exception....

"javax.mail.SendFailedException: Sending failed;"
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 450 <abcd@somesite.com>:Recipient address rejected: Domain not found......


So if i want to send hundereds of emails and if one of the Emails inbetween is Invalid the process Stops at that point and i could not send the other emails in the Loop......


How Could i Trap the exception thrown and handle it in such a way, so that the loops continues ..

Is there something with the SMTP Server....?

The code which i am using is as follows....


<Code>...

try {
InitialContext ic = new InitialContext();
Session session = (Session) ic.lookup(JNDINames.MAIL_SESSION);

if (Debug.debuggingOn)
session.setDebug(true);

// construct the message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(eMess.getEmailSender()));
String to = "";
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(eMess.getEmailReceiver(), false));
msg.setSubject(eMess.getSubject());
msg.setContent(eMess.getHtmlContents(),"text/plain");
msg.saveChanges();

Transport.send(msg);
} catch (Exception e) {
Debug.print("createAndSendMail exception : " + e);
throw new MailerAppException("Failure while sending mail");
}

</Code>....


Please give me any suggestions regarding it....and guide me accordingly..

Thanks a million in advance...
Regards
Sam
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2003
Added on Oct 14 2002
2 comments
782 views