下面的代码在java中用于发送电子邮件给我的团队中的人但是,它只适用于如果public static String to = "[email protected]";
但它不会工作,如果我有public static String to = "[email protected], [email protected]";
不知道我错过了什么,可以有人帮我发送电子邮件到多个ID与此同时 ?目前代码一次只能发送给一个人?Java代码发送电子邮件只适用于一个电子邮件ID?
public static String to = "[email protected], [email protected]";
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();
}
}
你试过添加多个收件人? – chrylis
Just have:String [] to = {“[email protected]”,“[email protected]”};并调用message.addRecipient(Message.RecipientType.TO,new InternetAddress(to [0])); message.addRecipient(Message.RecipientType.TO,new InternetAddress(to [1])); –
– tripleee