Search in sources :

Example 1 with MailPreparationException

use of org.springframework.mail.MailPreparationException in project BroadleafCommerce by BroadleafCommerce.

the class EmailServiceMDP method onMessage.

/*
     * (non-Javadoc)
     * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
     */
@SuppressWarnings("unchecked")
public void onMessage(Message message) {
    try {
        HashMap props = (HashMap) ((ObjectMessage) message).getObject();
        messageCreator.sendMessage(props);
    } catch (MailAuthenticationException e) {
        throw new EmailException(e);
    } catch (MailPreparationException e) {
        throw new EmailException(e);
    } catch (MailParseException e) {
        throw new EmailException(e);
    } catch (MailSendException e) {
        /*
             * TODO find the specific exception that results from the smtp
             * server being down, and throw this as an EmailException.
             * Otherwise, log and then swallow this exception, as it may have
             * been possible that this email was actually sent.
             */
        throw new EmailException(e);
    } catch (JMSException e) {
        throw new EmailException(e);
    }
}
Also used : MailPreparationException(org.springframework.mail.MailPreparationException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) MailSendException(org.springframework.mail.MailSendException) HashMap(java.util.HashMap) EmailException(org.broadleafcommerce.common.email.service.exception.EmailException) MailParseException(org.springframework.mail.MailParseException) JMSException(javax.jms.JMSException)

Example 2 with MailPreparationException

use of org.springframework.mail.MailPreparationException in project molgenis by molgenis.

the class ProgressImplTest method jobCanceledAndMailFails.

@Test
public void jobCanceledAndMailFails() {
    doThrow(new MailPreparationException("fail!")).when(mailSender).send(any(SimpleMailMessage.class));
    jobExecution.setProgressMessage("Downloading...");
    jobExecution.setFailureEmail("test@test");
    progress.start();
    progress.canceled();
    Mockito.verify(mailSender).send(any(SimpleMailMessage.class));
    assertEquals(jobExecution.getProgressMessage(), "Downloading... (Mail not sent: fail!)");
}
Also used : MailPreparationException(org.springframework.mail.MailPreparationException) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 3 with MailPreparationException

use of org.springframework.mail.MailPreparationException in project spring-framework by spring-projects.

the class JavaMailSenderImpl method send.

@Override
public void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException {
    try {
        List<MimeMessage> mimeMessages = new ArrayList<>(mimeMessagePreparators.length);
        for (MimeMessagePreparator preparator : mimeMessagePreparators) {
            MimeMessage mimeMessage = createMimeMessage();
            preparator.prepare(mimeMessage);
            mimeMessages.add(mimeMessage);
        }
        send(mimeMessages.toArray(new MimeMessage[0]));
    } catch (MailException ex) {
        throw ex;
    } catch (MessagingException ex) {
        throw new MailParseException(ex);
    } catch (Exception ex) {
        throw new MailPreparationException(ex);
    }
}
Also used : MailPreparationException(org.springframework.mail.MailPreparationException) MimeMessage(jakarta.mail.internet.MimeMessage) MessagingException(jakarta.mail.MessagingException) ArrayList(java.util.ArrayList) MailParseException(org.springframework.mail.MailParseException) MailException(org.springframework.mail.MailException) MailParseException(org.springframework.mail.MailParseException) NoSuchProviderException(jakarta.mail.NoSuchProviderException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) MessagingException(jakarta.mail.MessagingException) MailSendException(org.springframework.mail.MailSendException) MailPreparationException(org.springframework.mail.MailPreparationException) MailException(org.springframework.mail.MailException) AuthenticationFailedException(jakarta.mail.AuthenticationFailedException)

Example 4 with MailPreparationException

use of org.springframework.mail.MailPreparationException in project molgenis by molgenis.

the class ProgressImplTest method jobSucceedsButMailFails.

@Test
public void jobSucceedsButMailFails() {
    doThrow(new MailPreparationException("fail!")).when(mailSender).send(any(SimpleMailMessage.class));
    jobExecution.setProgressMessage("Job finished.");
    jobExecution.setSuccessEmail("test@test");
    progress.start();
    progress.success();
    Mockito.verify(mailSender).send(any(SimpleMailMessage.class));
    assertEquals(jobExecution.getProgressMessage(), "Job finished. (Mail not sent: fail!)");
}
Also used : MailPreparationException(org.springframework.mail.MailPreparationException) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 5 with MailPreparationException

use of org.springframework.mail.MailPreparationException in project molgenis by molgenis.

the class ProgressImplTest method jobFailsAndMailFails.

@Test
public void jobFailsAndMailFails() {
    doThrow(new MailPreparationException("fail!")).when(mailSender).send(any(SimpleMailMessage.class));
    jobExecution.setProgressMessage("Downloading...");
    jobExecution.setFailureEmail("test@test");
    progress.start();
    String exceptionMessage = "x is not a number";
    Exception ex = new IllegalArgumentException(exceptionMessage);
    progress.failed(ex);
    Mockito.verify(mailSender).send(any(SimpleMailMessage.class));
    assertEquals(jobExecution.getProgressMessage(), exceptionMessage + " (Mail not sent: fail!)");
}
Also used : MailPreparationException(org.springframework.mail.MailPreparationException) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailPreparationException(org.springframework.mail.MailPreparationException) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

MailPreparationException (org.springframework.mail.MailPreparationException)8 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)3 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)3 Test (org.testng.annotations.Test)3 AddressException (javax.mail.internet.AddressException)2 InternetAddress (javax.mail.internet.InternetAddress)2 MailAuthenticationException (org.springframework.mail.MailAuthenticationException)2 MailParseException (org.springframework.mail.MailParseException)2 MailSendException (org.springframework.mail.MailSendException)2 TemplateException (freemarker.template.TemplateException)1 AuthenticationFailedException (jakarta.mail.AuthenticationFailedException)1 MessagingException (jakarta.mail.MessagingException)1 NoSuchProviderException (jakarta.mail.NoSuchProviderException)1 MimeMessage (jakarta.mail.internet.MimeMessage)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1