Search in sources :

Example 96 with Message

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);
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Store(javax.mail.Store) Folder(javax.mail.Folder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 97 with Message

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);
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Store(javax.mail.Store) Folder(javax.mail.Folder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 98 with Message

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);
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Store(javax.mail.Store) Folder(javax.mail.Folder)

Example 99 with Message

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"));
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 100 with Message

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());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Message (javax.mail.Message)149 MimeMessage (javax.mail.internet.MimeMessage)81 MessagingException (javax.mail.MessagingException)53 InternetAddress (javax.mail.internet.InternetAddress)48 Folder (javax.mail.Folder)41 Test (org.junit.Test)40 Session (javax.mail.Session)37 Properties (java.util.Properties)36 Store (javax.mail.Store)28 Date (java.util.Date)19 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)19 MimeMultipart (javax.mail.internet.MimeMultipart)18 Mailbox (org.jvnet.mock_javamail.Mailbox)18 MimeBodyPart (javax.mail.internet.MimeBodyPart)16 PasswordAuthentication (javax.mail.PasswordAuthentication)15 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)13 Multipart (javax.mail.Multipart)13 Address (javax.mail.Address)11 HashMap (java.util.HashMap)8