use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.
the class SendHtmlTest method useEmailWorkItemHandlerWithAuthentication.
@Test
public void useEmailWorkItemHandlerWithAuthentication() throws Exception {
// Add authentication to Wiser SMTP server
wiser.getServer().setAuthenticationHandlerFactory(new TestAuthHandlerFactory());
// Input
String testMethodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String toAddress = "rgivens@yahoo.com";
String fromAddress = "rgivens@kty.us.gov";
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, emailPort, authUsername, authPassword);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", toAddress);
workItem.setParameter("From", fromAddress);
workItem.setParameter("Reply-To", fromAddress);
workItem.setParameter("Subject", "Test mail for " + testMethodName);
workItem.setParameter("Body", "Don't forget to check on Boyd later today.");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
List<WiserMessage> messages = wiser.getMessages();
assertEquals(1, messages.size());
for (WiserMessage wiserMessage : messages) {
MimeMessage message = wiserMessage.getMimeMessage();
assertEquals(workItem.getParameter("Subject"), message.getSubject());
assertTrue(Arrays.equals(InternetAddress.parse(toAddress), message.getRecipients(RecipientType.TO)));
}
}
use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.
the class EmailNotificationPublisherTest method testEmailNotificationWithTemplate.
@Test
public void testEmailNotificationWithTemplate() throws Exception {
EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo);
Map<String, Object> parameters = new HashMap<>();
parameters.put("Name", "John Doe");
Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newUser("john")));
publisher.publish("admin@jbpm.org", "Test notification", recipients, "basic-email", parameters);
assertEquals(1, wiser.getMessages().size());
String expectedBody = "<html><body>Hello John Doe</body></html>";
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
// Side effect of MIME encoding (I think.. ): \r\n..
String content = ((String) msg.getContent()).replace("\r\n", "");
assertEquals(expectedBody, content);
assertEquals("Test notification", msg.getSubject());
assertEquals("admin@jbpm.org", ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals("john@domain.com", ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
assertNull(msg.getRecipients(RecipientType.CC));
assertNull(msg.getRecipients(RecipientType.BCC));
}
Aggregations