use of javax.mail.Message in project camel by apache.
the class MailShutdownCompleteAllTasksTest 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].setText("Message " + i);
messages[i].setHeader("Message-ID", "" + i);
}
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.Message in project camel by apache.
the class MailPollEnrichTest 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, "bill", "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 MailPostProcessActionTest 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, "bill", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 1 new message
Message[] messages = new Message[1];
messages[0] = new MimeMessage(sender.getSession());
messages[0].setSubject("TestSubject");
messages[0].setHeader("Message-ID", "0");
messages[0].setText("TestText");
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.Message in project camel by apache.
the class MailUsingHeadersTest method testMailUsingHeaders.
@Test
public void testMailUsingHeaders() throws Exception {
Mailbox.clearAll();
// START SNIPPET: e1
Map<String, Object> map = new HashMap<String, Object>();
map.put("To", "davsclaus@apache.org");
map.put("From", "jstrachan@apache.org");
map.put("Subject", "Camel rocks");
map.put("CamelFileName", "fileOne");
map.put("org.apache.camel.test", "value");
String body = "Hello Claus.\nYes it does.\n\nRegards James.";
template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);
// END SNIPPET: e1
Mailbox box = Mailbox.get("davsclaus@apache.org");
Message msg = box.get(0);
assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
assertEquals("jstrachan@apache.org", msg.getFrom()[0].toString());
assertEquals("Camel rocks", msg.getSubject());
assertNull("We should not get the message header here", msg.getHeader("CamelFileName"));
assertNull("We should not get the message header here", msg.getHeader("org.apache.camel.test"));
}
use of javax.mail.Message in project camel by apache.
the class MailUsingHeadersTest method testMailWithFromInEndpoint.
@Test
public void testMailWithFromInEndpoint() throws Exception {
Mailbox.clearAll();
Map<String, Object> map = new HashMap<String, Object>();
map.put("Subject", "Camel rocks");
String body = "Hello Claus.\nYes it does.\n\nRegards James.";
template.sendBodyAndHeaders("smtp://davsclaus@apache.org?from=James Strachan <jstrachan@apache.org>&to=davsclaus@apache.org", body, map);
Mailbox box = Mailbox.get("davsclaus@apache.org");
Message msg = box.get(0);
assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
assertEquals("James Strachan <jstrachan@apache.org>", msg.getFrom()[0].toString());
assertEquals("Camel rocks", msg.getSubject());
}
Aggregations