Search in sources :

Example 61 with WiserMessage

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);
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Nonnull(javax.annotation.Nonnull)

Example 62 with WiserMessage

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());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) ArrayList(java.util.ArrayList) WiserMessage(org.subethamail.wiser.WiserMessage) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 63 with WiserMessage

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());
    }
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) ArrayList(java.util.ArrayList) WiserMessage(org.subethamail.wiser.WiserMessage) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 64 with WiserMessage

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));
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WiserMessage(org.subethamail.wiser.WiserMessage) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 65 with WiserMessage

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());
    }
}
Also used : BodyPart(javax.mail.BodyPart) Multipart(javax.mail.Multipart) MimeMessage(javax.mail.internet.MimeMessage) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WiserMessage(org.subethamail.wiser.WiserMessage) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Aggregations

WiserMessage (org.subethamail.wiser.WiserMessage)67 MimeMessage (javax.mail.internet.MimeMessage)34 Test (org.junit.Test)27 HashMap (java.util.HashMap)26 Deployment (org.activiti.engine.test.Deployment)22 ArrayList (java.util.ArrayList)12 MimeMultipart (javax.mail.internet.MimeMultipart)12 Deployment (org.camunda.bpm.engine.test.Deployment)10 Date (java.util.Date)9 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)6 InputStreamReader (java.io.InputStreamReader)5 Reader (java.io.Reader)5 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)5 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)5 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 File (java.io.File)4 LinkedHashSet (java.util.LinkedHashSet)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)4