@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())) {
            continue; // dealing with attachments only
        }
        assertEquals("email.png", bodyPart.getFileName());
    }
}