Search in sources :

Example 16 with MimeMessage

use of javax.mail.internet.MimeMessage in project camel by apache.

the class MailSortTermThreeTest method prepareMailbox.

private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, "bill", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();
    // inserts 3 messages, one with earlier, one with later sent date and one with invalid subject (not returned in search)
    Message[] messages = new Message[3];
    messages[0] = new MimeMessage(sender.getSession());
    messages[0].setText("Earlier date");
    messages[0].setHeader("Message-ID", "0");
    messages[0].setSentDate(new Date(10000));
    messages[0].setSubject("Camel");
    messages[1] = new MimeMessage(sender.getSession());
    messages[1].setText("Later date");
    messages[1].setHeader("Message-ID", "1");
    messages[1].setSentDate(new Date(20000));
    messages[1].setSubject("Camel");
    messages[2] = new MimeMessage(sender.getSession());
    messages[2].setText("Even later date");
    messages[2].setHeader("Message-ID", "2");
    messages[2].setSentDate(new Date(30000));
    messages[2].setSubject("Invalid");
    folder.appendMessages(messages);
    folder.close(true);
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Store(javax.mail.Store) Folder(javax.mail.Folder) Date(java.util.Date)

Example 17 with MimeMessage

use of javax.mail.internet.MimeMessage in project camel by apache.

the class MailSortTermTwoTest method prepareMailbox.

private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, "bill", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();
    // inserts 3 messages, one with earlier, one with later sent date and one with invalid subject (not returned in search)
    Message[] messages = new Message[3];
    messages[0] = new MimeMessage(sender.getSession());
    messages[0].setText("Earlier date");
    messages[0].setHeader("Message-ID", "0");
    messages[0].setSentDate(new Date(10000));
    messages[0].setSubject("Camel");
    messages[1] = new MimeMessage(sender.getSession());
    messages[1].setText("Later date");
    messages[1].setHeader("Message-ID", "1");
    messages[1].setSentDate(new Date(20000));
    messages[1].setSubject("Camel");
    messages[2] = new MimeMessage(sender.getSession());
    messages[2].setText("Even later date");
    messages[2].setHeader("Message-ID", "2");
    messages[2].setSentDate(new Date(30000));
    messages[2].setSubject("Invalid");
    folder.appendMessages(messages);
    folder.close(true);
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Store(javax.mail.Store) Folder(javax.mail.Folder) Date(java.util.Date)

Example 18 with MimeMessage

use of javax.mail.internet.MimeMessage in project sonarqube by SonarSource.

the class IssueNotificationsTest method notifications_for_bulk_change_ws.

/**
   * SONAR-4606
   */
@Test
public void notifications_for_bulk_change_ws() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.projectDate", "2015-12-15");
    Issues issues = issueClient.find(IssueQuery.create().componentRoots(PROJECT_KEY));
    Issue issue = issues.list().get(0);
    // bulk change without notification by default
    issuesService.bulkChange(BulkChangeRequest.builder().setIssues(singletonList(issue.key())).setAssign(USER_LOGIN).setSetSeverity("MINOR").build());
    // bulk change with notification
    issuesService.bulkChange(BulkChangeRequest.builder().setIssues(singletonList(issue.key())).setSetSeverity("BLOCKER").setSendNotifications(true).build());
    waitUntilAllNotificationsAreDelivered(2);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    emails.next();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("sample/Sample.xoo");
    assertThat((String) message.getContent()).contains("Severity: BLOCKER (was MINOR)");
    assertThat((String) message.getContent()).contains("See it in SonarQube: http://localhost:9000/issues/search#issues=" + issue.key());
    assertThat(emails.hasNext()).isFalse();
}
Also used : Issue(org.sonar.wsclient.issue.Issue) MimeMessage(javax.mail.internet.MimeMessage) Issues(org.sonar.wsclient.issue.Issues) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 19 with MimeMessage

use of javax.mail.internet.MimeMessage in project sonarqube by SonarSource.

the class EmailsTest method send_test_email.

@Test
public void send_test_email() throws Exception {
    updateEmailSettings("localhost", Integer.toString(SMTP_SERVER.getServer().getPort()), null, null, null, null, null);
    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();
    Iterator<WiserMessage> emails = SMTP_SERVER.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
    assertThat(message.getSubject()).contains("Test Message from SonarQube");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isFalse();
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 20 with MimeMessage

use of javax.mail.internet.MimeMessage in project sonarqube by SonarSource.

the class QualityGateNotificationTest method status_on_metric_variation_and_send_notifications.

@Test
public void status_on_metric_variation_and_send_notifications() throws Exception {
    setServerProperty(orchestrator, "email.smtp_host.secured", "localhost");
    setServerProperty(orchestrator, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
    // Create user, who will receive notifications for new violations
    userRule.createUser("tester", "Tester", "tester@example.org", "tester");
    // Send test email to the test user
    newAdminWsClient(orchestrator).wsConnector().call(new PostRequest("api/emails/send").setParam("to", "test@example.org").setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
    // Add notifications to the test user
    WsClient wsClient = newUserWsClient(orchestrator, "tester", "tester");
    wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewAlerts").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
    // Create quality gate with conditions on variations
    QualityGate simple = qgClient().create("SimpleWithDifferential");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").period(1).operator("EQ").warningThreshold("0"));
    SonarScanner analysis = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
    orchestrator.executeBuild(analysis);
    assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
    orchestrator.executeBuild(analysis);
    assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
    qgClient().unsetDefault();
    qgClient().destroy(simple.id());
    waitUntilAllNotificationsAreDelivered(smtpServer);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isTrue();
    message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("Quality gate status: Orange (was Green)");
    assertThat((String) message.getContent()).contains("Quality gate threshold: Lines of Code variation = 0 since previous analysis");
    assertThat((String) message.getContent()).contains("/dashboard/index/sample");
    assertThat(emails.hasNext()).isFalse();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newUserWsClient(util.ItUtils.newUserWsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)1146 Test (org.junit.Test)374 InternetAddress (javax.mail.internet.InternetAddress)334 MessagingException (javax.mail.MessagingException)299 Session (javax.mail.Session)222 Properties (java.util.Properties)219 MimeMultipart (javax.mail.internet.MimeMultipart)208 MimeBodyPart (javax.mail.internet.MimeBodyPart)178 Date (java.util.Date)153 IOException (java.io.IOException)137 Message (javax.mail.Message)120 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)107 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)97 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)83 InputStream (java.io.InputStream)82 ArrayList (java.util.ArrayList)81 Multipart (javax.mail.Multipart)75 DataHandler (javax.activation.DataHandler)73 ByteArrayOutputStream (java.io.ByteArrayOutputStream)72 BodyPart (javax.mail.BodyPart)70