Debug.logVerbose("What would have been sent, the addressee: " + sendTo + " subject: " + subject + " context: " + context, module);
results.put("messageWrapper", new MimeMessageWrapper(session, mail));
return results;
}
Transport trans = null;
try {
trans = session.getTransport("smtp");
if (!useSmtpAuth) {
trans.connect();
} else {
trans.connect(sendVia, authUser, authPass);
}
trans.sendMessage(mail, mail.getAllRecipients());
results.put("messageWrapper", new MimeMessageWrapper(session, mail));
results.put("messageId", mail.getMessageID());
trans.close();
} catch (SendFailedException e) {
// message code prefix may be used by calling services to determine the cause of the failure
String errMsg = "[ADDRERR] Address error when sending message to [" + sendTo + "] from [" + sendFrom + "] cc [" + sendCc + "] bcc [" + sendBcc + "] subject [" + subject + "]";
Debug.logError(e, errMsg, module);
List<SMTPAddressFailedException> failedAddresses = FastList.newInstance();
Exception nestedException = null;
while ((nestedException = e.getNextException()) != null && nestedException instanceof MessagingException) {
if (nestedException instanceof SMTPAddressFailedException) {
SMTPAddressFailedException safe = (SMTPAddressFailedException) nestedException;
Debug.logError("Failed to send message to [" + safe.getAddress() + "], return code [" + safe.getReturnCode() + "], return message [" + safe.getMessage() + "]", errMsg);
failedAddresses.add(safe);
break;
}
}
Boolean sendFailureNotification = (Boolean) context.get("sendFailureNotification");
if (sendFailureNotification == null || sendFailureNotification) {
sendFailureNotification(ctx, context, mail, failedAddresses);
results.put("messageWrapper", new MimeMessageWrapper(session, mail));
try {
results.put("messageId", mail.getMessageID());
trans.close();
} catch (MessagingException e1) {
Debug.logError(e1, module);
}
} else {
return ServiceUtil.returnError(errMsg);