public void sendMail(String from, String fromPersonal, List<String> to, String replyTo, String subject, String text) {
if( !started ) {
throw new RuntimeException("This mail sender is stopped");
}
try {
MimeMessage mm = new MimeMessage(getSession());
mm.setSubject(subject);
InternetAddress ia;
if( fromPersonal == null ) {
ia = new InternetAddress(from);
} else {
ia = new InternetAddress(from, fromPersonal);
}
mm.setFrom(ia);
Address[] add = new Address[1];
add[0] = new InternetAddress(replyTo);
mm.setReplyTo(add);
for (String sTo : to) {
if( sTo != null && sTo.length() > 0 ) {
InternetAddress recip = null;
try {
recip = new InternetAddress(sTo);
} catch (AddressException addressException) {
throw new RuntimeException("Couldnt parse email address: " + sTo, addressException);
}
mm.addRecipient(RecipientType.TO, recip);
}
}
mm.setContent(text, "text/plain");
sendMail(mm);
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException(ex);
} catch (MessagingException messagingException) {
throw new RuntimeException(messagingException);