Search in sources :

Example 11 with SmtpServer

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

the class SmtpTaskTest method test.

@Test
public void test() throws Exception {
    SmtpServer server = mail.getSmtp();
    SmtpTask t = new SmtpTask();
    t.send("localhost", server.getPort(), "my@mail.com", "their@mail.com", "test", "Hello!", "another@mail.com");
    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) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 12 with SmtpServer

use of com.icegreen.greenmail.smtp.SmtpServer in project syndesis by syndesisio.

the class EMailTestServer method getEmailsInFolder.

public List<EMailMessageModel> getEmailsInFolder(String user, String password, String folderName) throws Exception {
    if (server instanceof SmtpServer) {
        throw new Exception("SMTP not applicable for reading folders");
    }
    Store store = server.createStore();
    store.connect(user, password);
    Folder newFolder = store.getFolder(folderName);
    if (!newFolder.exists()) {
        throw new Exception("No folder with name " + folderName);
    }
    newFolder.open(Folder.READ_ONLY);
    List<EMailMessageModel> models = new ArrayList<>();
    for (Message msg : newFolder.getMessages()) {
        models.add(createMessageModel(msg));
    }
    return models;
}
Also used : EMailMessageModel(io.syndesis.connector.email.model.EMailMessageModel) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) ArrayList(java.util.ArrayList) Store(javax.mail.Store) KeyStore(java.security.KeyStore) Folder(javax.mail.Folder) MessagingException(javax.mail.MessagingException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

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