Hi,

Have you tried with try-catch at the appropriate place with a
`continue;' statement? Hint is given inline:

Thanks.
-SS.

------------------
> ssmtech wrote:
>
> Hello All,
>          I am using JavaMail API to send emails in a loop,but the
> problem is that, if any one of
> the email address in that loop is Invalid,it throws me an Exception as
> follows and the loop
> terminates....without send the remaining mails....
>
>
>
> "javax.mail.SendFailedException: Sending failed;
> nested exception is:
> javax.mail.SendFailedException:  Invalid Addresses;
> nested exception is:
> javax.mail.SendFailedException: 450 <[EMAIL PROTECTED]>:
> Recipient
> address rejected: Domain not found"
>
>
>
>        The Loop from where i am calling the JavaMail API(i.e MailBean)
> is as follows....
>
>
> <code>...// For Loop
>
> Object objEmail[] = emailAddressesCol.toArray();
> for(int j=0;j<objEmail.length;j++)
> {
> String emailAddresses = (String)objEmail[j];
> EMailMessage eMess = new
>
> EMailMessage(subject,message,emailAddresses,fromEmailAddress,newsLetterUrl);
> MailerHome mailerHome = EJBUtil.getMailerHome();
> Mailer mailer = mailerHome.create();
-------------------------------

/* The code below actually sends the mail and gets the exception for a
wrong address/domain. Thus put it in a try-catch, and test what
happens.*/

try {

> mailer.sendMail(eMess);

} catch(javax.mail.SendFailedException e) {
        continue;
}

/* Thus the ``continue;'' will go to the beginning of the loop, and
start trying with j incremented and the next address. */

--------------------------------
> }
>
> </code>...
>
>
>
> The code for sending mail in the JavaMail API (Mail Bean) is as
> follows....
>
> <code>...
>
> public void createAndSendMail(EMailMessage eMess) throws
> MailerAppException {
>
> 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);
> System.out.println ("The Email Has been Sent Successfully..... ");
>
> Debug.println("\nMail sent successfully.");
> } catch (Exception e) {
>     System.out.println ("the MailHelper step is............ 6 "+e);
>     Debug.print("createAndSendMail exception : " + e);
>     throw new MailerAppException("Failure while sending mail");
> }
> }//end of method...
>
>
>          I am sending hundereds of emails every day(into a loop one
> after the other) but the
> problem is that if any one of the email is Invalid in that loop, the
> loop gets Terminated at that
> Invalid Address and throws me an exception and because of which i
> could not send the remaining Emails....
>          What i really want to do is ...i want to catch the Exception
> because of an Invalid
> Address,handle it accordingly and continue with the loop,so that i
> will be able to send all the
> emails in that loop even though an exception has occurred.....
>
>  Can anybody guide me in this problem...any suggestions will be
> greatly appreciated...
>
> Thanks a million in Advance...
> Regards
> Sam
>
>
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to