1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| package mail;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class Main {
public static void main(String argv[]){
String[] emails = new String[] {
"niceandsimple@example.com",
"simplewith+symbol@example.com",
"less.common@example.com",
"a.little.more.unusual@dept.example.com",
"user@[IPv6:2001:db8:1ff::a0b:dbd0]",
"\"much.more\\ unusual\"@example.com",
"\"very.unusual.@.unusual.com\"@example.com",
"\"very.(),:;<>[]\\\".VERY.\\\"very@\\\\\\ \\\"very\\\".unusual\"@strange.example.com",
"0@a",
"!#$%&'*+-/=?^_`{}|~@example.org",
"\"()<>[]:,;@\\\\\\\"!#$%&'*+-/=?^_`{}|\\ \\ ~\\ \\ \\ ?\\ \\ \\ ^_`{}|~.a\"@example.org",
"\"\"@example.org",
"postbox@com" ,
"Abc.example.com",// (an @ character must separate the local and domain parts)
"Abc.@example.com", // (character dot(.) is last in local part)
"Abc..123@example.com", // (character dot(.) is double)
"A@b@c@example.com", // (only one @ is allowed outside quotation marks)
"a\"b(c)d,e:f;g<h>i[j\\k]l@example.com", // (none of the special characters in this local part is allowed outside quotation marks)
"just\"not\"right@example.com", // (quoted strings must be dot separated, or the only element making up the local-part)
"this is\"not\\allowed@example.com", // (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a slash)
"this\\ still\\\"not\\\\allowed@example.com", // (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes)
"patcat41@hotmail.fr"
};
for (String email: emails)
testMail(email);
}
private static boolean testMail(String email) {
try{
new InternetAddress(email,true);
System.out.printf("Adresse email <%s> ok\n",email);
return true;
} catch (AddressException e){
System.out.printf("Adresse email <%s> incorrecte: %s\n",email,e.getMessage());
return false;
}
}
} |
Partager