Search in sources :

Example 1 with MailParseException

use of org.springframework.mail.MailParseException 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[mimeMessages.size()]));
    } 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(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) MailParseException(org.springframework.mail.MailParseException) MailException(org.springframework.mail.MailException) MailParseException(org.springframework.mail.MailParseException) MessagingException(javax.mail.MessagingException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) MailSendException(org.springframework.mail.MailSendException) AuthenticationFailedException(javax.mail.AuthenticationFailedException) NoSuchProviderException(javax.mail.NoSuchProviderException) MailPreparationException(org.springframework.mail.MailPreparationException) MailException(org.springframework.mail.MailException)

Example 2 with MailParseException

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

the class JavaMailSenderTests method javaMailSenderWithParseExceptionOnSimpleMessage.

@Test
public void javaMailSenderWithParseExceptionOnSimpleMessage() {
    MockJavaMailSender sender = new MockJavaMailSender();
    SimpleMailMessage simpleMessage = new SimpleMailMessage();
    simpleMessage.setFrom("");
    try {
        sender.send(simpleMessage);
    } catch (MailParseException ex) {
        // expected
        assertTrue(ex.getCause() instanceof AddressException);
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) AddressException(javax.mail.internet.AddressException) MailParseException(org.springframework.mail.MailParseException) Test(org.junit.Test)

Example 3 with MailParseException

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

the class JavaMailSenderTests method javaMailSenderWithParseExceptionOnMimeMessagePreparator.

@Test
public void javaMailSenderWithParseExceptionOnMimeMessagePreparator() {
    MockJavaMailSender sender = new MockJavaMailSender();
    MimeMessagePreparator preparator = new MimeMessagePreparator() {

        @Override
        public void prepare(MimeMessage mimeMessage) throws MessagingException {
            mimeMessage.setFrom(new InternetAddress(""));
        }
    };
    try {
        sender.send(preparator);
    } catch (MailParseException ex) {
        // expected
        assertTrue(ex.getCause() instanceof AddressException);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) MailParseException(org.springframework.mail.MailParseException) Test(org.junit.Test)

Aggregations

MailParseException (org.springframework.mail.MailParseException)3 AddressException (javax.mail.internet.AddressException)2 MimeMessage (javax.mail.internet.MimeMessage)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 AuthenticationFailedException (javax.mail.AuthenticationFailedException)1 MessagingException (javax.mail.MessagingException)1 NoSuchProviderException (javax.mail.NoSuchProviderException)1 InternetAddress (javax.mail.internet.InternetAddress)1 MailAuthenticationException (org.springframework.mail.MailAuthenticationException)1 MailException (org.springframework.mail.MailException)1 MailPreparationException (org.springframework.mail.MailPreparationException)1 MailSendException (org.springframework.mail.MailSendException)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1