Java Code Examples for org.springframework.mail.MailParseException

The following examples show how to use org.springframework.mail.MailParseException. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: JavaMailSenderTests.java    License: 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 2
Source Project: java-technology-stack   Source File: JavaMailSenderTests.java    License: 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 3
Source Project: spring4-understanding   Source File: JavaMailSenderTests.java    License: 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 4
@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 5
Source Project: spring-analysis-note   Source File: JavaMailSenderImpl.java    License: MIT License 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 6
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 8
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 9
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 10
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 11
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 12
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 14
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 15
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 16
Source Project: spring-analysis-note   Source File: MimeMailMessage.java    License: MIT License 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 17
Source Project: spring-analysis-note   Source File: JavaMailSenderTests.java    License: MIT License 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 18
Source Project: java-technology-stack   Source File: JavaMailSenderImpl.java    License: MIT License 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 19
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 20
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 21
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 22
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 23
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 24
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 25
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 26
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 27
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 28
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 29
Source Project: java-technology-stack   Source File: MimeMailMessage.java    License: MIT License 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 30
Source Project: java-technology-stack   Source File: JavaMailSenderTests.java    License: MIT License 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);
	}
}