Hello Sir,
            I am working on an Enterprise Java Bean Application running on J2EE application server..Also using JavaMail API to send Emails through my application.
            I am able to send emails successfully through it and sending it into a loop one after the other...
            What i am tring to do is, if i encounter an Invalid Email Address the application throws me an SendFailedException and from this SendFailedException i want to catch Invalid Email Addresses... so that i will come to know which emails where sent and which were not...
 
        But the problem is that ,if an Invalid Email Address is encountered and after throwing me an SendFailedException if i try to Catch the Invalid Address ,like
            Address[] invalid = sfe.getInvalidAddresses();
and print an SOP after this,
            System.out.println("Collected InvalidAddress from SendFailedException...."+invalid);
the SOP prints "Null" ...
 
The Invalid Email Address is also an well Formed String....e.g...   "[EMAIL PROTECTED]"...
The complete Exception is .....

The exception is javax.mail.SendFailedException: Sending failed;  nested exception is: javax.mail.SendFailedException: 554 <[EMAIL PROTECTED]>: Recipient address rejected: Domain not found

The Code is ..

<Code>

    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();         
    try {
            Transport.send(msg);
            System.out.println ("The Email has been sent successfully....");
         } 
catch (javax.mail.SendFailedException sfe) {
        System.out.println("The exception in MailHelper is " + sfe);

    ArrayList al = new ArrayList();
    Collection badAddresses = null;
    System.out.println("Collecting InvalidAddress from SendFailedException....");
    Address[] invalid = sfe.getInvalidAddresses();
    System.out.println("Collected InvalidAddress from SendFailedException...."+invalid);//this SOP is Null....
    if (invalid != null) {
     System.out.println("Invalid Addresse(s) found......");
      if (invalid.length > 0) {
        for (int x = 0; x < invalid.length; x++) {
             invalidAddresses = invalid[x].toString();
             System.out.println("The Invalid Addresses are :"+invalidAddresses);          
         }         
      }
    }

</Code>

 

Can anybody help me out with this problem.Any suggestion or code can be greatly appreciated...

Thanks a million is advance...

Regards

Sam

Reply via email to