我正在尝试向N个人发送电子邮件。我已将gmail的电子邮件ID传递给名为toAddresses的值,因为我需要用逗号(,)分隔这些字符串元素
我使用了这种技术
String[] contactList=request.getParameterValues("mail_contacts");
InternetAddress[] toAddress = new InternetAddress[contactList.length];
for (int i = 0; i < contactList.length; i++) {
toAddress[i] = new InternetAddress(contactList[i]+",");
out.println("<p>"+toAddress[i]+"</p><p>"+toAddress[i].toString()+"</p>");
}
msg.setRecipients(Message.RecipientType.TO, toAddress);
但我从控制台收到一个错误 “缺少必需的标题'To'”
请帮我解决此错误
答案 0 :(得分:-1)
我不确定但是在你的代码中,toAddress是一个InetAdresses数组 当您设置要放置的联系人列表时:
msg.setRecipients(Message.RecipientType.TO, toAddress);
我相信toAddress应该是toAddress [数组的位置]我不完全确定尝试做:
String[] contactList=request.getParameterValues("mail_contacts");
InternetAddress[] toAddress = new InternetAddress[contactList.length];
for (int i = 0; i < contactList.length; i++) {
toAddress[i] = new InternetAddress(contactList[i]+",");
out.println("<p>"+toAddress[i]+"</p><p>"+toAddress[i].toString()+"</p>");
msg.setRecipients(Message.RecipientType.TO, toAddress[i]);
}