org.springframework.mail.MailParseException Java Examples

The following examples show how to use org.springframework.mail.MailParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleEmailServiceJavaMailSenderTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void testCreateMimeMessageWithExceptionInInputStream() throws Exception {
	InputStream inputStream = mock(InputStream.class);

	AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class);

	JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService);

	IOException ioException = new IOException("error");
	when(inputStream.read(ArgumentMatchers.any(byte[].class),
			ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt()))
					.thenThrow(ioException);

	try {
		mailSender.createMimeMessage(inputStream);
		fail("MailPreparationException expected due to error while creating mail");
	}
	catch (MailParseException e) {
		assertThat(e.getMessage().startsWith("Could not parse raw MIME content"))
				.isTrue();
		assertThat(e.getCause().getCause()).isSameAs(ioException);
	}
}
 
Example #2
Source File: JavaMailSenderTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #3
Source File: JavaMailSenderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
	}
}
 
Example #4
Source File: JavaMailSenderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
	}
}
 
Example #5
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCc(String[] cc) throws MailParseException {
	try {
		this.helper.setCc(cc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #6
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setFrom(String from) throws MailParseException {
	try {
		this.helper.setFrom(from);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #7
Source File: JavaMailSenderImpl.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException {
	try {
		return new MimeMessage(getSession(), contentStream);
	}
	catch (Exception ex) {
		throw new MailParseException("Could not parse raw MIME content", ex);
	}
}
 
Example #8
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setText(String text) throws MailParseException {
	try {
		this.helper.setText(text);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #9
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setSubject(String subject) throws MailParseException {
	try {
		this.helper.setSubject(subject);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #10
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setSentDate(Date sentDate) throws MailParseException {
	try {
		this.helper.setSentDate(sentDate);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #11
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setBcc(String[] bcc) throws MailParseException {
	try {
		this.helper.setBcc(bcc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #12
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setBcc(String bcc) throws MailParseException {
	try {
		this.helper.setBcc(bcc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #13
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setTo(String to) throws MailParseException {
	try {
		this.helper.setTo(to);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #14
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCc(String cc) throws MailParseException {
	try {
		this.helper.setCc(cc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #15
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setTo(String[] to) throws MailParseException {
	try {
		this.helper.setTo(to);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #16
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setTo(String to) throws MailParseException {
	try {
		this.helper.setTo(to);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #17
Source File: MimeMailMessage.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setReplyTo(String replyTo) throws MailParseException {
	try {
		this.helper.setReplyTo(replyTo);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #18
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setReplyTo(String replyTo) throws MailParseException {
	try {
		this.helper.setReplyTo(replyTo);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #19
Source File: JavaMailSenderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException {
	try {
		return new MimeMessage(getSession(), contentStream);
	}
	catch (Exception ex) {
		throw new MailParseException("Could not parse raw MIME content", ex);
	}
}
 
Example #20
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setTo(String[] to) throws MailParseException {
	try {
		this.helper.setTo(to);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #21
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setCc(String cc) throws MailParseException {
	try {
		this.helper.setCc(cc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #22
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setCc(String[] cc) throws MailParseException {
	try {
		this.helper.setCc(cc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #23
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setBcc(String bcc) throws MailParseException {
	try {
		this.helper.setBcc(bcc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #24
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setBcc(String[] bcc) throws MailParseException {
	try {
		this.helper.setBcc(bcc);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #25
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setSentDate(Date sentDate) throws MailParseException {
	try {
		this.helper.setSentDate(sentDate);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #26
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setSubject(String subject) throws MailParseException {
	try {
		this.helper.setSubject(subject);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #27
Source File: MimeMailMessage.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setText(String text) throws MailParseException {
	try {
		this.helper.setText(text);
	}
	catch (MessagingException ex) {
		throw new MailParseException(ex);
	}
}
 
Example #28
Source File: JavaMailSenderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #29
Source File: SimpleEmailServiceJavaMailSender.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException {
	try {
		return new MimeMessage(getSession(), contentStream);
	}
	catch (MessagingException e) {
		throw new MailParseException("Could not parse raw MIME content", e);
	}
}
 
Example #30
Source File: SmtpMailer.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
@Override
public MimeMessage createMimeMessage(InputStream contentStream) {
    try {
        return new CustomMimeMessage(getSession(), contentStream);
    }
    catch (MessagingException ex) {
        throw new MailParseException("Could not parse raw MIME content", ex);
    }
}