Search in sources :

Example 46 with MailException

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);
        }
    }
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) MailException(org.springframework.mail.MailException)

Example 47 with MailException

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;
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) HashMap(java.util.HashMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Aggregations

MailException (org.springframework.mail.MailException)47 MimeMessage (javax.mail.internet.MimeMessage)18 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)17 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)15 MessagingException (javax.mail.MessagingException)10 Date (java.util.Date)8 Properties (java.util.Properties)3 InternetAddress (javax.mail.internet.InternetAddress)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 AuthenticationFailedException (jakarta.mail.AuthenticationFailedException)2 MessagingException (jakarta.mail.MessagingException)2 NoSuchProviderException (jakarta.mail.NoSuchProviderException)2 MimeMessage (jakarta.mail.internet.MimeMessage)2 PrintWriter (java.io.PrintWriter)2 URI (java.net.URI)2 Matcher (java.util.regex.Matcher)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 MolgenisDataException (org.molgenis.data.MolgenisDataException)2