Example usage for javax.mail.internet MimeMessage getHeader

List of usage examples for javax.mail.internet MimeMessage getHeader

Introduction

In this page you can find the example usage for javax.mail.internet MimeMessage getHeader.

Prototype

@Override
public String getHeader(String name, String delimiter) throws MessagingException 

Source Link

Document

Get all the headers for this header name, returned as a single String, with headers separated by the delimiter.

Usage

From source file:org.sonarqube.tests.settings.EmailsTest.java

@Test
public void send_customized_test_email() throws Exception {
    String from = randomAlphanumeric(4) + "@" + randomAlphabetic(5);
    String fromName = randomAlphanumeric(5);
    String prefix = randomAlphanumeric(6);
    updateEmailSettings("localhost", Integer.toString(SMTP_SERVER.getServer().getPort()), from, fromName,
            prefix, null, null, null);/* w w w  .ja va  2s .  c  om*/

    sendEmail("test@example.org", "Test Message from SonarQube", "This is a test message from SonarQube");

    // We need to wait until all notifications will be delivered
    waitUntilAllNotificationsAreDelivered(1);
    Iterator<WiserMessage> emails = SMTP_SERVER.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(Arrays.stream(message.getFrom()).map(Address::toString))
            .containsOnly(format("%s <%s>", fromName, from));
    assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
    assertThat(message.getSubject()).isEqualTo(prefix + " Test Message from SonarQube");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isFalse();
}