List of usage examples for javax.mail MessagingException MessagingException
public MessagingException()
From source file:com.zimbra.cs.mailclient.smtp.SmtpTransportTest.java
@Test(timeout = 3000) public void dataException() throws Exception { server = MockTcpServer.scenario().sendLine("220 test ready").recvLine() // EHLO .sendLine("250 OK").recvLine() // MAIL FROM .sendLine("250 OK").recvLine() // RCPT TO .sendLine("250 OK").recvLine() // DATA .sendLine("354 OK").swallowUntil("\r\n.\r\n").build().start(PORT); Session session = JMSession.getSession(); Transport transport = session.getTransport("smtp"); transport.connect("localhost", PORT, null, null); String raw = "From: sender@zimbra.com\nTo: rcpt@zimbra.com\nSubject: test\n\ntest"; MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1))) { @Override/*from ww w . ja v a2 s . c o m*/ public void writeTo(OutputStream os, String[] ignoreList) throws MessagingException { throw new MessagingException(); // exception while encoding } }; try { transport.sendMessage(msg, msg.getAllRecipients()); Assert.fail(); } catch (SendFailedException expected) { } finally { transport.close(); } server.shutdown(1000); Assert.assertEquals("EHLO localhost\r\n", server.replay()); Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay()); Assert.assertEquals("RCPT TO:<rcpt@zimbra.com>\r\n", server.replay()); Assert.assertEquals("DATA\r\n", server.replay()); Assert.assertNull(server.replay()); }
From source file:org.apache.james.transport.mailets.delivery.MailDispatcherTest.java
@Test public void errorsShouldBeWellHandled() throws Exception { MailDispatcher testee = MailDispatcher.builder().log(mock(Log.class)).mailetContext(fakeMailContext) .mailStore(mailStore).consume(true).build(); doThrow(new MessagingException()).when(mailStore).storeMail(any(MailAddress.class), any(Mail.class)); MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder() .setMultipartWithBodyParts(MimeMessageBuilder.bodyPartBuilder().data("toto").build()).build(); FakeMail mail = FakeMail.builder().sender(MailAddressFixture.OTHER_AT_JAMES).mimeMessage(mimeMessage) .recipients(MailAddressFixture.ANY_AT_JAMES).state("state").build(); testee.dispatch(mail);//from www. j av a 2s .c o m List<FakeMailContext.SentMail> actual = fakeMailContext.getSentMails(); FakeMailContext.SentMail expected = FakeMailContext.sentMailBuilder() .sender(MailAddressFixture.OTHER_AT_JAMES).recipient(MailAddressFixture.ANY_AT_JAMES) .state(Mail.ERROR).build(); assertThat(actual).containsOnly(expected); assertThat(IOUtils.toString(actual.get(0).getMsg().getInputStream(), Charsets.UTF_8)).contains("toto"); }