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);
}
}
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);
}
}
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);
}
}
Aggregations