In our application we use java mail to send emails. Every thing was working fine until a new requirement has come to send an email to an id which takes the form testUser@em_company.com (The part which causes JavaMail to throw an exception is the fact that email address contains _ in the domain name. (em_company.com).
In our code I'm initializing InternetAddress like :
//harding coding toAddress for simplicity
String toAddress = "testUser@em_company.com";
InternetAddress address = new InternetAddress(toAddress);
After looking in the code (Java Mail 1.4.4)
Class : InternetAddress
Method : private static void checkAddress(String addr,
boolean routeAddr, boolean validate)
throws AddressException
I see a check which causes this exception :
if (!(Character.isLetterOrDigit(c) || c == '-' || c == '.'))
throw new AddressException(
"Domain contains illegal character", addr);
So the question is, is there any way that we can bypass this check and ask java Mail not to do validation check on domain name.