rendered paste body public void sendEmails() {
for(String email: emails) {
new EmailMailer(session,from,email,subject,body,mime);
}
}
class EmailMailer implements Runnable {
private Session session;
private String from;
private String to;
private String subject;
private String body;
private String mime;
public EmailMailer(Session session,String from,String to,String subject, String body,String mime) {
this.session = session;
this.from = from;
this.to = to;
this.subject = subject;
this.body = body;
this.mime = mime;
new Thread(this);
}
public void run() {
try {
final Message msg = new MimeMessage(session);
final Address from = new InternetAddress(this.from);
final Address whom = new InternetAddress(this.to);
msg.setContent(body,mime);
msg.setFrom(from);
msg.setRecipient(Message.RecipientType.TO, whom);
msg.setSubject(subject);
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Issue email transportation to " + this.to);
}
}
}