if(mailProvider == null) {
return;
}
Session session = mailProvider.getSession();
Message message = new MimeMessage(session);
// n.b. any default from address is expected to be determined by caller.
if (! StringUtils.isEmpty(from)) {
InternetAddress sentFrom = new InternetAddress(from);
message.setFrom(sentFrom);
if (log.isDebugEnabled()) log.debug("e-mail from: " + sentFrom);
}
if (to!=null) {
InternetAddress[] sendTo = new InternetAddress[to.length];
for (int i = 0; i < to.length; i++) {
sendTo[i] = new InternetAddress(to[i]);
if (log.isDebugEnabled()) log.debug("sending e-mail to: " + to[i]);
}
message.setRecipients(Message.RecipientType.TO, sendTo);
}
if (cc != null) {
InternetAddress[] copyTo = new InternetAddress[cc.length];
for (int i = 0; i < cc.length; i++) {
copyTo[i] = new InternetAddress(cc[i]);
if (log.isDebugEnabled()) log.debug("copying e-mail to: " + cc[i]);
}
message.setRecipients(Message.RecipientType.CC, copyTo);
}
if (bcc != null) {
InternetAddress[] copyTo = new InternetAddress[bcc.length];
for (int i = 0; i < bcc.length; i++) {
copyTo[i] = new InternetAddress(bcc[i]);
if (log.isDebugEnabled()) log.debug("blind copying e-mail to: " + bcc[i]);
}
message.setRecipients(Message.RecipientType.BCC, copyTo);
}
message.setSubject((subject == null) ? "(no subject)" : subject);
message.setContent(content, mimeType);
message.setSentDate(new java.util.Date());
// First collect all the addresses together.
Address[] remainingAddresses = message.getAllRecipients();
int nAddresses = remainingAddresses.length;
boolean bFailedToSome = false;
SendFailedException sendex = new SendFailedException("Unable to send message to some recipients");