use of com.icegreen.greenmail.smtp.SmtpServer in project syndesis by syndesisio.
the class EMailTestServer method generateFolder.
public void generateFolder(String user, String password, String folderName) throws Exception {
if (server instanceof SmtpServer) {
throw new Exception("SMTP not applicable for generating folders");
}
Store store = server.createStore();
store.connect(user, password);
Folder newFolder = store.getFolder(folderName);
if (!newFolder.exists()) {
newFolder.create(Folder.HOLDS_MESSAGES);
assertTrue(newFolder.exists());
}
newFolder.open(Folder.READ_WRITE);
assertTrue(newFolder.isOpen());
List<MimeMessage> msgs = new ArrayList<>();
for (int i = 1; i <= 5; ++i) {
// Use random content to avoid potential residual lingering problems
String subject = folderName + SPACE + HYPHEN + SPACE + GreenMailUtil.random();
String body = folderName + NEW_LINE + GreenMailUtil.random();
GreenMailUser greenUser = greenMail.setUser(user, password);
// Construct message
msgs.add(createTextMessage(greenUser.getEmail(), "Ben" + i + "@test.com", subject, body));
}
newFolder.appendMessages(msgs.toArray(new MimeMessage[0]));
assertEquals(msgs.size(), newFolder.getMessageCount());
}
use of com.icegreen.greenmail.smtp.SmtpServer in project syndesis by syndesisio.
the class EMailTestServer method getEmailCountInFolder.
public int getEmailCountInFolder(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);
return newFolder.getMessageCount();
}
use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.
the class SmtpTaskTest method testAttachments.
@Test
public void testAttachments() 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());
mailParams.put("attachments", Collections.singletonList(new File(ClassLoader.getSystemResource("attahcment.txt").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(1, messages.length);
MimeMessage msg = messages[0];
assertNotNull(msg.getContent());
assertTrue(msg.getContent() instanceof MimeMultipart);
MimeMultipart mp = (MimeMultipart) msg.getContent();
assertEquals(2, mp.getCount());
assertEquals("Hello, Concord!", mp.getBodyPart(0).getContent());
assertEquals("test-attachment", mp.getBodyPart(1).getContent());
mail.reset();
}
use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.
the class SmtpTaskTest method testMultipleToComma.
@Test
public void testMultipleToComma() 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, 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();
}
use of com.icegreen.greenmail.smtp.SmtpServer in project concord by walmartlabs.
the class SmtpTaskTest method testNoBccViaCall.
@Test
public void testNoBccViaCall() throws Exception {
SmtpServer server = mail.getSmtp();
Map<String, Object> smtpParams = new HashMap<>();
Map<String, Object> mailParams = new HashMap<>();
smtpParams.put("host", "localhost");
smtpParams.put("port", server.getPort());
mailParams.put("from", "my@mail.com");
mailParams.put("to", "their@mail.com");
mailParams.put("subject", "test");
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());
assertEquals(1, messages[0].getAllRecipients().length);
mail.reset();
}
Aggregations