Search in sources :

Example 11 with Message

use of javax.mail.Message in project camel by apache.

the class MailCustomContentTypeTest method testSendPlainMailContentTypeInHeader.

@Test
public void testSendPlainMailContentTypeInHeader() throws Exception {
    Mailbox.clearAll();
    template.sendBodyAndHeader("direct:b", "Hello World", "contentType", "text/plain; charset=iso-8859-1");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertEquals("text/plain; charset=iso-8859-1", msg.getContentType());
    assertEquals("Hello World", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 12 with Message

use of javax.mail.Message in project camel by apache.

the class MailCustomContentTypeTest method testSendPlainMailContentTypeInHeader2.

@Test
public void testSendPlainMailContentTypeInHeader2() throws Exception {
    Mailbox.clearAll();
    template.sendBodyAndHeader("direct:b", "Hello World", Exchange.CONTENT_TYPE, "text/plain; charset=iso-8859-1");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertEquals("text/plain; charset=iso-8859-1", msg.getContentType());
    assertEquals("Hello World", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 13 with Message

use of javax.mail.Message in project camel by apache.

the class MailCustomContentTypeTest method testSendHtmlMail.

@Test
public void testSendHtmlMail() throws Exception {
    Mailbox.clearAll();
    sendBody("direct:a", "<html><body><h1>Hello</h1>World</body></html>");
    Mailbox box = Mailbox.get("claus@localhost");
    Message msg = box.get(0);
    assertTrue(msg.getContentType().startsWith("text/html"));
    assertEquals("text/html; charset=UTF-8", msg.getContentType());
    assertEquals("<html><body><h1>Hello</h1>World</body></html>", msg.getContent());
}
Also used : Mailbox(org.jvnet.mock_javamail.Mailbox) Message(javax.mail.Message) Test(org.junit.Test)

Example 14 with Message

use of javax.mail.Message in project camel by apache.

the class NestedMimeMessageConsumeTest method prepareMailbox.

private void prepareMailbox(String user) throws MessagingException {
    // connect to mailbox
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, user, "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();
    InputStream is = getClass().getResourceAsStream("/nested-multipart.elm");
    Message hurzMsg = new MimeMessage(sender.getSession(), is);
    Message[] messages = new Message[] { hurzMsg };
    // insert one signed message
    folder.appendMessages(messages);
    folder.close(true);
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) InputStream(java.io.InputStream) Store(javax.mail.Store) Folder(javax.mail.Folder)

Example 15 with Message

use of javax.mail.Message in project camel by apache.

the class RawMailMessageTest method testGetRawJavaMailMessage.

@Test
public void testGetRawJavaMailMessage() throws Exception {
    Mailbox.clearAll();
    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");
    String body = "Hello Claus.\nYes it does.\n\nRegards James.";
    getMockEndpoint("mock:mail").expectedMessageCount(1);
    template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);
    assertMockEndpointsSatisfied();
    Exchange exchange = getMockEndpoint("mock:mail").getReceivedExchanges().get(0);
    // START SNIPPET: e1
    // get access to the raw javax.mail.Message as shown below
    Message javaMailMessage = exchange.getIn(MailMessage.class).getMessage();
    assertNotNull(javaMailMessage);
    assertEquals("Camel rocks", javaMailMessage.getSubject());
// END SNIPPET: e1
}
Also used : Exchange(org.apache.camel.Exchange) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Message (javax.mail.Message)132 MimeMessage (javax.mail.internet.MimeMessage)69 MessagingException (javax.mail.MessagingException)49 InternetAddress (javax.mail.internet.InternetAddress)40 Test (org.junit.Test)40 Folder (javax.mail.Folder)37 Properties (java.util.Properties)32 Session (javax.mail.Session)31 Store (javax.mail.Store)28 Date (java.util.Date)19 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)19 Mailbox (org.jvnet.mock_javamail.Mailbox)18 MimeMultipart (javax.mail.internet.MimeMultipart)15 MimeBodyPart (javax.mail.internet.MimeBodyPart)14 PasswordAuthentication (javax.mail.PasswordAuthentication)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 Multipart (javax.mail.Multipart)11 Address (javax.mail.Address)9 HashMap (java.util.HashMap)7