use of org.springframework.mail.MailException in project alfresco-repository by Alfresco.
the class MailActionExecuter method sendEmail.
private void sendEmail(final Action ruleAction, MimeMessageHelper preparedMessage) {
try {
// Send the message unless we are in "testMode"
if (!testMode) {
mailService.send(preparedMessage.getMimeMessage());
onSend();
} else {
lastTestMessage = preparedMessage.getMimeMessage();
testSentCount++;
}
} catch (NullPointerException | MailException e) {
onFail();
String to = (String) ruleAction.getParameterValue(PARAM_TO);
if (to == null) {
Object obj = ruleAction.getParameterValue(PARAM_TO_MANY);
if (obj != null) {
to = obj.toString();
}
}
// always log the failure
logger.error("Failed to send email to " + to + " : " + e);
// optionally ignore the throwing of the exception
Boolean ignoreError = (Boolean) ruleAction.getParameterValue(PARAM_IGNORE_SEND_FAILURE);
if (ignoreError == null || ignoreError.booleanValue() == false) {
throw new AlfrescoRuntimeException("Failed to send email to:" + to);
}
}
}
use of org.springframework.mail.MailException in project alfresco-repository by Alfresco.
the class MailActionExecuter method sendTestMessage.
/**
* Send a test message
*
* @return true, message sent
* @throws AlfrescoRuntimeException
*/
public boolean sendTestMessage() {
if (testMessageTo == null || testMessageTo.length() == 0) {
throw new AlfrescoRuntimeException("email.outbound.err.test.no.to");
}
if (testMessageSubject == null || testMessageSubject.length() == 0) {
throw new AlfrescoRuntimeException("email.outbound.err.test.no.subject");
}
if (testMessageText == null || testMessageText.length() == 0) {
throw new AlfrescoRuntimeException("email.outbound.err.test.no.text");
}
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(PARAM_TO, testMessageTo);
params.put(PARAM_SUBJECT, testMessageSubject);
params.put(PARAM_TEXT, testMessageText);
Action ruleAction = serviceRegistry.getActionService().createAction(NAME, params);
MimeMessageHelper message = prepareEmail(ruleAction, null, new Pair<String, Locale>(testMessageTo, getLocaleForUser(testMessageTo)), getFrom(ruleAction));
try {
mailService.send(message.getMimeMessage());
onSend();
} catch (MailException me) {
onFail();
StringBuffer txt = new StringBuffer();
txt.append(me.getClass().getName() + ", " + me.getMessage());
Throwable cause = me.getCause();
while (cause != null) {
txt.append(", ");
txt.append(cause.getClass().getName() + ", " + cause.getMessage());
cause = cause.getCause();
}
Object[] args = { testMessageTo, txt.toString() };
throw new AlfrescoRuntimeException("email.outbound.err.send.failed", args, me);
}
return true;
}
Aggregations