2011-05-25 191 views
0

我試圖發送電子郵件給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); 

但我正在逐漸從一個錯誤控制檯它說 「缺少必需的頭‘要’」

請幫我解決這個錯誤

+0

我不認爲你需要的創建新的InternetAddress時使用逗號。 – Swati 2011-05-25 21:12:45

+0

@Swati:java.io.IOException異常:無內容 \t javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:108) \t javax.activation.DataHandler.writeTo(DataHandler.java:305) \t的javax。 mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1383) \t javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1743) \t javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1719) \t com.mpigeon.SendMails.doPost(SendMails.java:167) \t javax.servlet.http.HttpServlet.service(HttpServlet.java:637) \t javax.servl et.http.HttpServlet.service(HttpServlet.java:717)我在控制檯中得到這個異常 – 2011-05-25 21:27:26

+0

'com.mpigeon.SendMails'中有什麼? – Swati 2011-05-26 14:13:53

回答

-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]); 
} 
相關問題