use of org.subethamail.wiser.WiserMessage in project simple-java-mail by bbottema.
the class SmtpServerRule method getMessage.
@Nonnull
public MimeMessage getMessage(String envelopeReceiver) throws MessagingException {
checkState("getMessages()");
List<WiserMessage> messages = getMessages();
Iterator<WiserMessage> iterator = messages.iterator();
while (iterator.hasNext()) {
WiserMessage wiserMessage = iterator.next();
if (wiserMessage.getEnvelopeReceiver().equals(envelopeReceiver)) {
MimeMessage mimeMessage = wiserMessage.getMimeMessage();
iterator.remove();
return mimeMessage;
}
}
throw new AssertionError("message not found for recipient " + envelopeReceiver);
}
use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testMultipleToWithSingleCCAndBCC.
@Test
public void testMultipleToWithSingleCCAndBCC() throws Exception {
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, emailPort, null, null);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", "person1@domain.com; person2@domain.com");
workItem.setParameter("Cc", "person3@domain.com; person4@domain.com");
workItem.setParameter("Bcc", "person5@domain.com; person6@domain.com");
workItem.setParameter("From", "person4@domain.com");
workItem.setParameter("Reply-To", "person5@domain.com");
workItem.setParameter("Subject", "Subject 1");
workItem.setParameter("Body", "Body 1");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
assertEquals(6, wiser.getMessages().size());
List<String> list = new ArrayList<String>(6);
for (int i = 0; i < 6; ++i) {
list.add(wiser.getMessages().get(i).getEnvelopeReceiver());
}
for (int i = 1; i < 7; ++i) {
assertTrue(list.contains("person" + i + "@domain.com"));
}
// We know from previous test that all MimeMessages will be identical
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
assertEquals(workItem.getParameter("From"), wiser.getMessages().get(0).getEnvelopeSender());
String content = ((String) msg.getContent()).replace("\r\n", "");
assertEquals(workItem.getParameter("Body"), content);
assertEquals(workItem.getParameter("Subject"), msg.getSubject());
assertEquals(workItem.getParameter("From"), ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals(workItem.getParameter("Reply-To"), ((InternetAddress) msg.getReplyTo()[0]).getAddress());
assertEquals(workItem.getParameter("To"), ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress() + "; " + ((InternetAddress) msg.getRecipients(RecipientType.TO)[1]).getAddress());
assertEquals(workItem.getParameter("Cc"), ((InternetAddress) msg.getRecipients(RecipientType.CC)[0]).getAddress() + "; " + ((InternetAddress) msg.getRecipients(RecipientType.CC)[1]).getAddress());
}
use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testSingleToWithSingleCCAndBCC.
@Test
public void testSingleToWithSingleCCAndBCC() throws Exception {
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, emailPort, null, null);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", "person1@domain.com");
workItem.setParameter("Cc", "person2@domain.com");
workItem.setParameter("Bcc", "person3@domain.com");
workItem.setParameter("From", "person4@domain.com");
workItem.setParameter("Reply-To", "person5@domain.com");
workItem.setParameter("Subject", "Subject 1");
workItem.setParameter("Body", "Body 1");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
assertEquals(3, wiser.getMessages().size());
List<String> list = new ArrayList<String>(3);
list.add(wiser.getMessages().get(0).getEnvelopeReceiver());
list.add(wiser.getMessages().get(1).getEnvelopeReceiver());
list.add(wiser.getMessages().get(2).getEnvelopeReceiver());
assertTrue(list.contains("person1@domain.com"));
assertTrue(list.contains("person2@domain.com"));
assertTrue(list.contains("person3@domain.com"));
for (int i = 0; i < wiser.getMessages().size(); ++i) {
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(i)).getMimeMessage();
assertEquals(workItem.getParameter("From"), wiser.getMessages().get(i).getEnvelopeSender());
String content = ((String) msg.getContent()).replace("\r\n", "");
assertEquals(workItem.getParameter("Body"), content);
assertEquals(workItem.getParameter("Subject"), msg.getSubject());
assertEquals(workItem.getParameter("From"), ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals(workItem.getParameter("Reply-To"), ((InternetAddress) msg.getReplyTo()[0]).getAddress());
assertEquals(workItem.getParameter("To"), ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
assertEquals(workItem.getParameter("Cc"), ((InternetAddress) msg.getRecipients(RecipientType.CC)[0]).getAddress());
}
}
use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testSingleTo.
@Test
public void testSingleTo() throws Exception {
EmailWorkItemHandler handler = new EmailWorkItemHandler();
handler.setConnection(emailHost, emailPort, null, null);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("To", "person1@domain.com");
workItem.setParameter("From", "person2@domain.com");
workItem.setParameter("Reply-To", "person3@domain.com");
workItem.setParameter("Subject", "Subject 1");
workItem.setParameter("Body", "Body 1");
WorkItemManager manager = new DefaultWorkItemManager(null);
handler.executeWorkItem(workItem, manager);
assertEquals(1, wiser.getMessages().size());
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(workItem.getParameter("Body"), content);
assertEquals(workItem.getParameter("Subject"), msg.getSubject());
assertEquals(workItem.getParameter("From"), ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals(workItem.getParameter("Reply-To"), ((InternetAddress) msg.getReplyTo()[0]).getAddress());
assertEquals(workItem.getParameter("To"), ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
assertNull(msg.getRecipients(RecipientType.CC));
assertNull(msg.getRecipients(RecipientType.BCC));
}
use of org.subethamail.wiser.WiserMessage in project jbpm by kiegroup.
the class SendHtmlTest method sendHtmlWithAuthenticationAndAttachments.
@Test
public void sendHtmlWithAuthenticationAndAttachments() throws Exception {
// Add authentication to Wiser SMTP server
wiser.getServer().setAuthenticationHandlerFactory(new TestAuthHandlerFactory());
// Input
String testMethodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String toAddress = "rgivens@kty.us.gov";
String fromAddress = "whawkins@kty.us.gov";
// Setup email
WorkItemImpl workItem = createEmailWorkItemWithAttachment(toAddress, fromAddress, testMethodName);
Connection connection = new Connection(emailHost, emailPort, authUsername, authPassword);
// send email
Email email = emailWorkItemHandler.createEmail(workItem, connection);
SendHtml.sendHtml(email, connection);
List<WiserMessage> messages = wiser.getMessages();
assertEquals(1, messages.size());
MimeMessage message = messages.get(0).getMimeMessage();
assertEquals(workItem.getParameter("Subject"), message.getSubject());
assertTrue(Arrays.equals(InternetAddress.parse((String) workItem.getParameter("To")), message.getRecipients(RecipientType.TO)));
assertTrue(message.getContent() instanceof Multipart);
Multipart multipart = (Multipart) message.getContent();
assertEquals(2, multipart.getCount());
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
if (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition())) {
// dealing with attachments only
continue;
}
assertEquals("email.gif", bodyPart.getFileName());
}
}
Aggregations