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-----------


Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine

Create Nested table inside a table on a pdf document using iText