我正在尝试使用JavaMail向多个收件人发送邮件。每条消息的内容都是不同的。该程序向不同的收件人发送电子邮件,但内容相同。谁能帮我。她是我的源代码。
public static void postMail(String[] recipients, String subject, Timestamp time)throws MessagingException {
String nachricht = null;
String link = null;
Session session = MailUtil.getGMailSession("username", "password");
Message msg = new MimeMessage(session);
msg.setSubject(subject);
for(int i=0; i<=recipients.length-1;i++){
System.out.println(recipients[i]);
link = recipients[i] + "/" + time;
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[i]));
}//endOf forSchleife
message = link
msg.setContent(message, "text/plain");
Transport.send(msg);
}
答案 0 :(得分:0)
I think that the code should be like below:
for(int i=0; i<=recipients.length-1;i++){
Message msg = new MimeMessage(session);
msg.setSubject(subject);
System.out.println(recipients[i]);
link = recipients[i] + "/" + time;
//msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[i]));
//Try this please
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients[i]));
message = link
msg.setContent(message, "text/plain");
Transport.send(msg);
}//endOf forSchleife
inside of the for loop...