呵呵,你看看这段代码。import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;public class MailExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String to = args[2]; // Get system properties
Properties props = System.getProperties(); // Setup mail server
props.put("mail.smtp.host", host); // Get session
Session session = Session.getDefaultInstance(props, null); // Define message
MimeMessage message = new MimeMessage(session); // Set the from address
message.setFrom(new InternetAddress(from)); // Set the to address
/*
你在这里多加几个不就实现群发了吗,或者使用addRecipients方法
至于发送用户的来源吗,可以是文件,那就将用户一条一条读出来,
然后用addRecipent了,只是个循环的问题了,呵呵。
*/
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to)); // Set the subject
message.setSubject("Hello JavaMail"); // Set the content
message.setText("Welcome to JavaMail"); // Send message
Transport.send(message);
}
}
import javax.mail.*;
import javax.mail.internet.*;public class MailExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String to = args[2]; // Get system properties
Properties props = System.getProperties(); // Setup mail server
props.put("mail.smtp.host", host); // Get session
Session session = Session.getDefaultInstance(props, null); // Define message
MimeMessage message = new MimeMessage(session); // Set the from address
message.setFrom(new InternetAddress(from)); // Set the to address
/*
你在这里多加几个不就实现群发了吗,或者使用addRecipients方法
至于发送用户的来源吗,可以是文件,那就将用户一条一条读出来,
然后用addRecipent了,只是个循环的问题了,呵呵。
*/
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to)); // Set the subject
message.setSubject("Hello JavaMail"); // Set the content
message.setText("Welcome to JavaMail"); // Send message
Transport.send(message);
}
}
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, to);
~~~ 接收者(InternetAddress[]类型)
发送即可,将信发给 to 中的每一个地址,实现群发