List of usage examples for javax.mail.internet MimeMessage getHeader
@Override public String getHeader(String name, String delimiter) throws MessagingException
From source file:org.sonar.plugins.emailnotifications.EmailNotificationChannelTest.java
@Test public void shouldSendTestEmail() throws Exception { configure();// w ww . j a v a 2s .c om channel.sendTestEmail("user@nowhere", "Test Message from Sonar", "This is a test message from Sonar."); List<WiserMessage> messages = server.getMessages(); assertThat(messages.size(), is(1)); MimeMessage email = messages.get(0).getMimeMessage(); assertThat(email.getHeader("Content-Type", null), is("text/plain; charset=UTF-8")); assertThat(email.getHeader("From", ","), is("Sonar <server@nowhere>")); assertThat(email.getHeader("To", null), is("<user@nowhere>")); assertThat(email.getHeader("Subject", null), is("[SONAR] Test Message from Sonar")); assertThat((String) email.getContent(), startsWith("This is a test message from Sonar.")); }
From source file:org.sonar.plugins.emailnotifications.EmailNotificationChannelTest.java
@Test public void shouldSendThreadedEmail() throws Exception { configure();//from w w w . j a va 2 s . c o m EmailMessage emailMessage = new EmailMessage().setMessageId("reviews/view/1").setFrom("Full Username") .setTo("user@nowhere").setSubject("Review #3").setMessage("I'll take care of this violation."); channel.deliver(emailMessage); List<WiserMessage> messages = server.getMessages(); assertThat(messages.size(), is(1)); MimeMessage email = messages.get(0).getMimeMessage(); assertThat(email.getHeader("Content-Type", null), is("text/plain; charset=UTF-8")); assertThat(email.getHeader("In-Reply-To", null), is("<reviews/view/1@nemo.sonarsource.org>")); assertThat(email.getHeader("References", null), is("<reviews/view/1@nemo.sonarsource.org>")); assertThat(email.getHeader("List-ID", null), is("Sonar <sonar.nemo.sonarsource.org>")); assertThat(email.getHeader("List-Archive", null), is("http://nemo.sonarsource.org")); assertThat(email.getHeader("From", ","), is("\"Full Username (Sonar)\" <server@nowhere>")); assertThat(email.getHeader("To", null), is("<user@nowhere>")); assertThat(email.getHeader("Subject", null), is("[SONAR] Review #3")); assertThat((String) email.getContent(), startsWith("I'll take care of this violation.")); }
From source file:org.sonar.plugins.emailnotifications.EmailNotificationChannelTest.java
@Test public void shouldSendNonThreadedEmail() throws Exception { configure();//w w w. j a v a 2 s .c o m EmailMessage emailMessage = new EmailMessage().setTo("user@nowhere").setSubject("Foo").setMessage("Bar"); channel.deliver(emailMessage); List<WiserMessage> messages = server.getMessages(); assertThat(messages.size(), is(1)); MimeMessage email = messages.get(0).getMimeMessage(); assertThat(email.getHeader("Content-Type", null), is("text/plain; charset=UTF-8")); assertThat(email.getHeader("In-Reply-To", null), nullValue()); assertThat(email.getHeader("References", null), nullValue()); assertThat(email.getHeader("List-ID", null), is("Sonar <sonar.nemo.sonarsource.org>")); assertThat(email.getHeader("List-Archive", null), is("http://nemo.sonarsource.org")); assertThat(email.getHeader("From", null), is("Sonar <server@nowhere>")); assertThat(email.getHeader("To", null), is("<user@nowhere>")); assertThat(email.getHeader("Subject", null), is("[SONAR] Foo")); assertThat((String) email.getContent(), startsWith("Bar")); }
From source file:org.sonar.server.notification.email.EmailNotificationChannelTest.java
@Test public void shouldSendTestEmail() throws Exception { configure();/*from w w w. ja v a 2s . c o m*/ underTest.sendTestEmail("user@nowhere", "Test Message from SonarQube", "This is a test message from SonarQube."); List<WiserMessage> messages = smtpServer.getMessages(); assertThat(messages).hasSize(1); MimeMessage email = messages.get(0).getMimeMessage(); assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube <server@nowhere>"); assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube"); assertThat((String) email.getContent()).startsWith("This is a test message from SonarQube."); }
From source file:org.sonar.server.notification.email.EmailNotificationChannelTest.java
@Test public void shouldSendThreadedEmail() throws Exception { configure();/*from ww w . j a v a 2 s.c om*/ EmailMessage emailMessage = new EmailMessage().setMessageId("reviews/view/1").setFrom("Full Username") .setTo("user@nowhere").setSubject("Review #3").setMessage("I'll take care of this violation."); underTest.deliver(emailMessage); List<WiserMessage> messages = smtpServer.getMessages(); assertThat(messages).hasSize(1); MimeMessage email = messages.get(0).getMimeMessage(); assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); assertThat(email.getHeader("In-Reply-To", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>"); assertThat(email.getHeader("References", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>"); assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>"); assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube)\" <server@nowhere>"); assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3"); assertThat((String) email.getContent()).startsWith("I'll take care of this violation."); }
From source file:org.sonar.server.notification.email.EmailNotificationChannelTest.java
@Test public void shouldSendNonThreadedEmail() throws Exception { configure();/* w ww.jav a 2s .co m*/ EmailMessage emailMessage = new EmailMessage().setTo("user@nowhere").setSubject("Foo").setMessage("Bar"); underTest.deliver(emailMessage); List<WiserMessage> messages = smtpServer.getMessages(); assertThat(messages).hasSize(1); MimeMessage email = messages.get(0).getMimeMessage(); assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); assertThat(email.getHeader("In-Reply-To", null)).isNull(); assertThat(email.getHeader("References", null)).isNull(); assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>"); assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); assertThat(email.getHeader("From", null)).isEqualTo("SonarQube <server@nowhere>"); assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>"); assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Foo"); assertThat((String) email.getContent()).startsWith("Bar"); }
From source file:org.sonarqube.tests.issue.IssueNotificationsTest.java
@Test public void notifications_for_personalized_emails() throws Exception { String version = RandomStringUtils.randomAlphanumeric(10); // 1st analysis without any issue (because no file is analyzed) createSampleProject(privateProject ? "private" : "public"); createUsers();/*ww w . j a v a 2s . co m*/ tester.settings().setGlobalSettings("sonar.issues.defaultAssigneeLogin", userWithUserRole.getLogin()); runAnalysis("issue/xoo-with-scm", "sonar.projectVersion", version, "sonar.scm.provider", "xoo", "sonar.scm.disabled", "false", "sonar.exclusions", "**/*"); // No email since all code is ignored waitUntilAllNotificationsAreDelivered(1); assertThat(smtpServer.getMessages()).isEmpty(); // run 2nd analysis which will generate issues on the leak period runAnalysis("issue/xoo-with-scm", "sonar.projectVersion", version, "sonar.scm.provider", "xoo", "sonar.scm.disabled", "false"); // We expect to receive a notification for each subscriber with UserRole.user // And a personalized email for the assignee userWithUserRole waitUntilAllNotificationsAreDelivered(privateProject ? 3 : 4); assertThat(smtpServer.getMessages()).hasSize(privateProject ? 3 : 4); // the last email sent is the personalized one MimeMessage message = smtpServer.getMessages().get(privateProject ? 2 : 3).getMimeMessage(); assertThat(message.getHeader("To", null)).isEqualTo(format("<%s>", userWithUserRole.getEmail())); assertThat(message.getSubject()).contains("You have 13 new issues"); assertThat((String) message.getContent()).contains("Project: Sample").contains("Version: " + version); }
From source file:org.sonarqube.tests.issue.IssueNotificationsTest.java
void checkEmailSettings() throws Exception { // Send test email to the test user tester.wsClient().wsConnector().call(new PostRequest("api/emails/send").setParam("to", EMAIL_TEST) .setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful(); // We need to wait until all notifications will be delivered waitUntilAllNotificationsAreDelivered(1); assertThat(smtpServer.getMessages()).hasSize(1); MimeMessage message = smtpServer.getMessages().get(0).getMimeMessage(); assertThat(message.getHeader("To", null)).isEqualTo("<" + EMAIL_TEST + ">"); assertThat((String) message.getContent()).contains("This is a test message from SonarQube"); }
From source file:org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesNotificationTest.java
private String getAllRecipients(MimeMessage mimeMessage) { try {/*from w ww . java2 s . c om*/ return mimeMessage.getHeader("To", null); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:org.sonarqube.tests.settings.EmailsTest.java
@Test public void send_test_email() throws Exception { updateEmailSettings("localhost", Integer.toString(SMTP_SERVER.getServer().getPort()), null, null, null, null, null, null);/*from w ww. ja v a2 s .c o m*/ 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("SonarQube <noreply@nowhere>"); assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>"); assertThat(message.getSubject()).isEqualTo("[SONARQUBE] Test Message from SonarQube"); assertThat((String) message.getContent()).contains("This is a test message from SonarQube"); assertThat(emails.hasNext()).isFalse(); }