我想将邮件发送给特定的用户群而不是单独的电子邮件收件人?或者是否有办法从列表中获取个人用户并向每个用户发送邮件。
此致
答案 0 :(得分:0)
您可以使用有Sender和Receiver的JMS(Java消息服务)。并且,一个发送者可以同时发送给多个接收者。
答案 1 :(得分:0)
这个方法我们可以使用
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class SendEmail {
public void SendingEmail(String Email, String Body) throws AddressException, MessagingException {
String host = "smtp.gmail.com";
String from = "test.myemail@.com"; // Your mail id
String pass = "PASSWORD"; // Your Password
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, pass);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("senanayakaamesh@gmail.com"));// ur email
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(Email));// u will send to Email
message.setSubject("Use this code as Sequrity code ");
message.setText(Body);
MimeBodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
System.out.println("sending");
Transport.send(message);
System.out.println("Done");
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String args[]) {
try {
SendingEmail("to email", "Massage");
System.out.println("sucess ending");
} catch (Exception e) {
// TODO: handle exception
}
}
}