Search in sources :

Example 6 with SmtpServer

use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.

the class SmtpTaskTest method testNoMessage.

@Test
public void testNoMessage() throws Exception {
    SmtpServer server = mail.getSmtp();
    Map<String, Object> smtpParams = new HashMap<>();
    smtpParams.put("host", "localhost");
    smtpParams.put("port", server.getPort());
    Map<String, Object> mailParams = new HashMap<>();
    mailParams.put("from", "my@mail.com");
    mailParams.put("to", "aaa@mail.com");
    mailParams.put("subject", "test");
    try {
        SmtpTask t = new SmtpTask();
        t.call(smtpParams, mailParams);
        fail("should fail");
    } catch (IllegalArgumentException e) {
    // expected
    }
    mail.reset();
}
Also used : SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 7 with SmtpServer

use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.

the class SmtpTaskTest method testNoSubject.

@Test
public void testNoSubject() throws Exception {
    SmtpServer server = mail.getSmtp();
    Map<String, Object> smtpParams = new HashMap<>();
    smtpParams.put("host", "localhost");
    smtpParams.put("port", server.getPort());
    Map<String, Object> mailParams = new HashMap<>();
    mailParams.put("from", "my@mail.com");
    mailParams.put("to", "aaa@mail.com");
    mailParams.put("message", "Hello!");
    SmtpTask t = new SmtpTask();
    t.call(smtpParams, mailParams);
    MimeMessage[] messages = mail.getReceivedMessages();
    assertEquals(1, messages.length);
    assertEquals("Hello!\r\n", messages[0].getContent());
    mail.reset();
}
Also used : SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 8 with SmtpServer

use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.

the class SmtpTaskTest method testNoBcc.

@Test
public void testNoBcc() throws Exception {
    SmtpServer server = mail.getSmtp();
    SmtpTask t = new SmtpTask();
    t.send("localhost", server.getPort(), "my@mail.com", "their@mail.com", "test", "Hello!", null);
    MimeMessage[] messages = mail.getReceivedMessages();
    assertEquals(1, messages.length);
    assertEquals("Hello!\r\n", messages[0].getContent());
    assertEquals(1, messages[0].getAllRecipients().length);
    mail.reset();
}
Also used : SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 9 with SmtpServer

use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.

the class SmtpTaskTest method testMultipleTo.

@Test
public void testMultipleTo() throws Exception {
    SmtpServer server = mail.getSmtp();
    Map<String, Object> smtpParams = new HashMap<>();
    smtpParams.put("host", "localhost");
    smtpParams.put("port", server.getPort());
    Map<String, Object> mailParams = new HashMap<>();
    mailParams.put("from", "my@mail.com");
    mailParams.put("to", Arrays.asList("aaa@mail.com", "bbb@mail.com"));
    mailParams.put("subject", "test");
    mailParams.put("message", "Hello!");
    SmtpTask t = new SmtpTask();
    t.call(smtpParams, mailParams);
    MimeMessage[] messages = mail.getReceivedMessages();
    assertEquals(2, messages.length);
    assertEquals("Hello!\r\n", messages[0].getContent());
    mail.reset();
}
Also used : SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 10 with SmtpServer

use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.

the class SmtpTaskTest method testVariables.

@Test
public void testVariables() throws Exception {
    SmtpServer server = mail.getSmtp();
    Map<String, Object> smtpParams = new HashMap<>();
    smtpParams.put("host", "localhost");
    smtpParams.put("port", server.getPort());
    Map<String, Object> mailParams = new HashMap<>();
    mailParams.put("from", "my@mail.com");
    mailParams.put("to", "their@mail.com");
    mailParams.put("template", new File(ClassLoader.getSystemResource("test.mustache").toURI()).toString());
    Map<String, Object> m = new HashMap<>();
    m.put("name", "Concord");
    m.put("workDir", "/");
    m.put("smtp", smtpParams);
    m.put("mail", mailParams);
    Context ctx = new MockContext(m);
    SmtpTask t = new SmtpTask();
    t.execute(ctx);
    MimeMessage[] messages = mail.getReceivedMessages();
    assertEquals("Hello, Concord!\r\n", messages[0].getContent());
    mail.reset();
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) Context(com.walmartlabs.concord.sdk.Context) MockContext(com.walmartlabs.concord.sdk.MockContext) SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) File(java.io.File) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

SmtpServer (com.icegreen.greenmail.smtp.SmtpServer)12 MimeMessage (javax.mail.internet.MimeMessage)10 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)7 IOException (java.io.IOException)3 KeyStore (java.security.KeyStore)3 KeyStoreException (java.security.KeyStoreException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 Folder (javax.mail.Folder)3 MessagingException (javax.mail.MessagingException)3 Store (javax.mail.Store)3 Context (com.walmartlabs.concord.sdk.Context)2 MockContext (com.walmartlabs.concord.sdk.MockContext)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 GreenMailUser (com.icegreen.greenmail.user.GreenMailUser)1 EMailMessageModel (io.syndesis.connector.email.model.EMailMessageModel)1 Message (javax.mail.Message)1 MimeMultipart (javax.mail.internet.MimeMultipart)1