gpt4 book ai didi

发送电子邮件的Java代码仅适用于一个电子邮件ID?

转载 作者:行者123 更新时间:2023-12-02 05:54:07 25 4
gpt4 key购买 nike

我使用下面的java代码向我团队中的人员发送电子邮件,但是它只有在public static String to =“marsh@gmail.com”;时才有效,但它不会工作如果我有 public static String to = "marsh@gmail.com, mark@gmail.com"; 不确定我缺少什么,有人可以帮助我同时向多个 ID 发送电子邮件吗?目前该代码一次只能发送给一个人?

public static String to = "marsh@gmail.com, mark@gmail.com";
public static String from= "SANDBOX";
public static String host = "localhost";

public static void send_production_email(String reportDate){

System.out.println("Preparing to Send Email to Admin's...");

Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);

Session session = Session.getDefaultInstance(properties);

try{

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

message.setSubject(" Production Database Backed up Successfully");

message.setContent("<h4> Production Database Backup Completed on" +reportDate+" </h4><br>"
+ "<h4>Please do not respond to this email as this is an auto generated email</h4></br>"
+"<h4>Thank You!</h4></br>" );
Transport.send(message);
System.out.println("Sent message successfully....");
}
catch (MessagingException mex) {
mex.printStackTrace();
}

}

最佳答案

您需要为每个电子邮件地址调用 message.addRecipient() 或使用地址数组调用 addRecipients()

关于发送电子邮件的Java代码仅适用于一个电子邮件ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23258715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com