javax.mail.internet.AddressException: Local address contains control or whitespace in string

Problem:

javax.mail.internet.AddressException: Local address contains control or whitespace in string 

at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:114)
at example.Test2.processFolder(Test2.java:151)
at example.Test2.processFolder(Test2.java:64)
at example.Test2.processFolder(Test2.java:64)
at example.Test2.processFolder(Test2.java:64)
at example.Test2.<init>(Test2.java:43)
at example.Test2.main(Test2.java:33)



Solution: 
**************************************Code Snippet**********************
InternetAddress[] address_old = unicodifyAddresses(toMail);
msg.setRecipients(Message.RecipientType.CC, unicodifyAddresses(email.getDisplayCC()));


// Here is the function which will remove white space



InternetAddress[] unicodifyAddresses(String addresses) throws AddressException {
    InternetAddress[] recipent = InternetAddress.parse(addresses, false);
    for(int i=0; i<recipent.length; i++) {
        try {
            recipent[i] = new InternetAddress(recipent[i].getAddress(), recipent[i].getPersonal(), "utf-8");
        } catch(UnsupportedEncodingException uee) {
            throw new RuntimeException("utf-8 not valid encoding?", uee);
        }
    }
    return recipent;
}
************************************************************************

Please visit http://stackoverflow.com/questions/2656478/send-javax-mail-internet-mimemessage-to-a-recipient-with-non-ascii-name
------Referneced  from www.stackoverflow.com-----------


Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Read Excel using Apache POI - Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException:

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'