Q:

parse "from" address in email in javamail

I am trying to read emails from my inbox using javamail and I am specifically checking for emails that have the subject "Delivery Status Notification". Here's the code:
for(Message message:messages){
            for(Address a:message.getFrom()){
                if(message.getSubject().equalsIgnoreCase("Delivery Status Notification")){
                Multipart mp=(Multipart)message.getContent();                                        
                for(int i=0;i<mp.getCount();i++) {
                    BodyPart bodyPart = mp.getBodyPart(i);
                    if (bodyPart.isMimeType("text/*")) {
                    String cont = (String) bodyPart.getContent();
                    System.out.println("Content: "+cont);
                    }
                }                    
                System.out.println("-----\n");
               }
            }

The problem is that the sender of these notifications is the "Mail Delivery System" and the line

Address a:message.getFrom()

throws the error -- " javax.mail.internet.AddressException: Local address contains control or whitespace in string ``Mail Delivery System'' ".
How do I parse this address without having to catch the exception and then work with it?
Thanks for any help.

A:

Some mail servers send these delivery notification messages using a bogus and illegal From address.  You should, of course, report this bug to the mail server vendor.
While you're waiting for the vendor to fix their problem, you can work around it in JavaMail by setting the following Session property:
  session.setProperty("mail.mime.address.strict", "false");

