java mail 发送邮件 多个收件人和抄送人,存在一个收件人的邮箱账号不存在(并不是格式不合法),到时发送失败
String[] address = new String[2];
address[0] = "1198819501@qq.com";
address[1] = "444woaini12345678904@qq.com";
InternetAddress[] tos= new InternetAddress[address.length];
for (int i = 0; i < address.length; i++) {
if(!address[i].trim().matches("^\w+([-+.]\w+)*@\w+([-.]\w+)+$")){
System.exit(-1);
}
tos[i] = new InternetAddress(address[i].trim());
}
String[] address1= new String[2];
address1[0] = "jiamei.zhang@tiaokefu.com";
address1[1] = "jiamei1123345663344.zhang@yit.com";
InternetAddress[] cc= new InternetAddress[address.length];
for (int i = 0; i < address1.length; i++) {
if(!address1[i].trim().matches("^\w+([-+.]\w+)*@\w+([-.]\w+)+$")){
System.exit(-1);
}
cc[i] = new InternetAddress(address1[i].trim());
}
msg.setRecipients(Message.RecipientType.TO, tos);
msg.setRecipients(Message.RecipientType.CC, cc);
这是网上找到的解决方案,我想请教一下原理。