简体   繁体   English

向多个收件人发送电子邮件

[英]Sending emails to multiple recipients

I am trying to send emails to N number of people.我正在尝试向 N 人发送电子邮件。 I have passed the email id of gmail to a value called toAddresses, since I need to separate those string elements with comma (,)我已将 gmail 的 email id 传递给名为 toAddresses 的值,因为我需要用逗号 (,) 分隔这些字符串元素

I used this technique我使用了这种技术

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);

But I am getting an error from the console which says "Missing required header 'To'"但是我从控制台收到一条错误消息,上面写着“缺少所需的 header 'To'”

Kindly help me resolve this error请帮我解决这个错误

I am not sure but in your code toAddress is an array of InetAdresses and when you are setting the contact list you are putting:我不确定,但在您的代码中 toAddress 是一个 InetAdresses 数组,当您设置联系人列表时,您正在放置:

msg.setRecipients(Message.RecipientType.TO, toAddress);

I believe toAddress Should be toAddress[position of array] I'm not entirely sure try doing:我相信 toAddress 应该是 toAddress[position of array] 我不完全确定尝试这样做:

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]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM