Currently, mail servers usually do not accept non-ASCII characters in the local part, only the part of the domain (after the "@" sign) is supported with IDN.
To encode only part of a domain using the java.net.IDN class, I use the following Util.
(The code is not tested in production, but it should work)
import java.net.IDN; public class IDNMailHelper { public static String toIdnAddress(String mail) { if (mail == null) { return null; } int idx = mail.indexOf('@'); if (idx < 0) { return mail; } return localPart(mail, idx) + "@" + IDN.toASCII(domain(mail, idx)); } private static String localPart(String mail, int idx) { return mail.substring(0, idx); } private static String domain(String mail, int idx) { return mail.substring(idx + 1); } }
felix source share