Reputation: 41
While trying to READ the email addressee of an email coming from Outlook:
message.getRecipients(Message.RecipientType.TO)
I am getting following exception:
Caused by: javax.mail.internet.AddressException: Domain contains illegal character in string ``'[email protected]'''
at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1269)
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1091)
at javax.mail.internet.InternetAddress.parseHeader(InternetAddress.java:658)
at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:701)
at javax.mail.internet.MimeMessage.getRecipients(MimeMessage.java:534)
The problem is given by this character " ' " at the beginning and at the end of the email address. The problem is that for the outlook server this is a valid address but not for a MimeMessage, so when I am trying to retrieve it and all the checks are applied I am getting the exception.
Please note that I am not creating the message, I am just reading whatever is in the outlook inbox folder through:
Folder inbox = store.getFolder(.......);
messages = inbox.getMessages();
Any idea how to solve/workaround this?
Thank you very much Sam
Upvotes: 4
Views: 6258
Reputation: 3244
I suspect you are using java mail version higher than 1.4 which by defaults enables strict RFC822 syntax
You could able to read email with quotes by disabling "strict" policy on InternetAddress something like this.
Properties props = new Properties();
props.setProperty("mail.mime.address.strict", "false");
Session session = Session.getDefaultInstance(props, ....);
Or simply
new InternetAddress("...", false);
Upvotes: 6