use of javax.mail.Message in project camel by apache.
the class MailCommitOnCompletionTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "jones", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 5 new messages
Message[] messages = new Message[5];
for (int i = 0; i < 5; i++) {
messages[i] = new MimeMessage(sender.getSession());
messages[i].setHeader("Message-ID", "" + i);
messages[i].setText("Message " + i);
}
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.Message in project camel by apache.
the class MailContentTypeTest method testSendMultipartMail.
@Test
public void testSendMultipartMail() throws Exception {
Mailbox.clearAll();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(MailConstants.MAIL_ALTERNATIVE_BODY, "Hello World");
sendBody("direct:c", "<html><body><h1>Hello</h1>World</body></html>", headers);
Mailbox box = Mailbox.get("claus@localhost");
Message msg = box.get(0);
assertTrue(msg.getContentType().startsWith("multipart/alternative"));
assertEquals("Hello World", ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent());
assertEquals("<html><body><h1>Hello</h1>World</body></html>", ((MimeMultipart) msg.getContent()).getBodyPart(1).getContent());
}
use of javax.mail.Message in project camel by apache.
the class MailConvertersTest method testMultipartToInputStream.
@Test
public void testMultipartToInputStream() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.send("direct:a", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(MailConstants.MAIL_ALTERNATIVE_BODY, "Alternative World");
}
});
assertMockEndpointsSatisfied();
Message mailMessage = mock.getReceivedExchanges().get(0).getIn().getBody(MailMessage.class).getMessage();
assertNotNull(mailMessage);
Object content = mailMessage.getContent();
assertIsInstanceOf(Multipart.class, content);
InputStream is = mock.getReceivedExchanges().get(0).getIn().getBody(InputStream.class);
assertNotNull(is);
assertEquals("Alternative World", context.getTypeConverter().convertTo(String.class, is));
}
use of javax.mail.Message in project camel by apache.
the class MailConvertersTest method testMailMessageToInputStream.
@Test
public void testMailMessageToInputStream() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBodyAndHeader("direct:a", "Hello World", "Subject", "Camel rocks");
assertMockEndpointsSatisfied();
Message mailMessage = mock.getReceivedExchanges().get(0).getIn().getBody(MailMessage.class).getMessage();
assertNotNull(mailMessage);
InputStream is = MailConverters.toInputStream(mailMessage);
assertNotNull(is);
assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, is));
}
use of javax.mail.Message in project camel by apache.
the class MailConvertersTest method testMultipartToByteArray.
@Test
public void testMultipartToByteArray() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.send("direct:a", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(MailConstants.MAIL_ALTERNATIVE_BODY, "Alternative World");
}
});
assertMockEndpointsSatisfied();
Message mailMessage = mock.getReceivedExchanges().get(0).getIn().getBody(MailMessage.class).getMessage();
assertNotNull(mailMessage);
Object content = mailMessage.getContent();
assertIsInstanceOf(Multipart.class, content);
byte[] is = mock.getReceivedExchanges().get(0).getIn().getBody(byte[].class);
assertNotNull(is);
assertEquals("Alternative World", context.getTypeConverter().convertTo(String.class, is));
}
Aggregations