Search in sources :

Example 1 with EmailMessage

use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.

the class ReportAnalysisFailureNotificationEmailTemplate method format.

@Override
@CheckForNull
public EmailMessage format(Notification notification) {
    if (!(notification instanceof ReportAnalysisFailureNotification)) {
        return null;
    }
    ReportAnalysisFailureNotificationBuilder taskFailureNotification = serializer.fromNotification((ReportAnalysisFailureNotification) notification);
    String projectUuid = taskFailureNotification.getProject().getUuid();
    String projectFullName = computeProjectFullName(taskFailureNotification.getProject());
    return new EmailMessage().setMessageId(notification.getType() + "/" + projectUuid).setSubject(subject(projectFullName)).setPlainTextMessage(message(projectFullName, taskFailureNotification));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) CheckForNull(javax.annotation.CheckForNull)

Example 2 with EmailMessage

use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.

the class EmailNotificationChannel method deliver.

@Override
public boolean deliver(Notification notification, String username) {
    if (!isActivated()) {
        LOG.debug(SMTP_HOST_NOT_CONFIGURED_DEBUG_MSG);
        return false;
    }
    User user = findByLogin(username);
    if (user == null || StringUtils.isBlank(user.email())) {
        LOG.debug("User does not exist or has no email: {}", username);
        return false;
    }
    EmailMessage emailMessage = format(notification);
    if (emailMessage != null) {
        emailMessage.setTo(user.email());
        return deliver(emailMessage);
    }
    return false;
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) User(org.sonar.api.user.User)

Example 3 with EmailMessage

use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.

the class EmailNotificationChannel method sendTestEmail.

/**
 * Send test email.
 *
 * @throws EmailException when unable to send
 */
public void sendTestEmail(String toAddress, String subject, String message) throws EmailException {
    try {
        EmailMessage emailMessage = new EmailMessage();
        emailMessage.setTo(toAddress);
        emailMessage.setSubject(subject);
        emailMessage.setPlainTextMessage(message + getServerBaseUrlFooter());
        send(emailMessage);
    } catch (EmailException e) {
        LOG.debug("Fail to send test email to {}: {}", toAddress, e);
        throw e;
    }
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) EmailException(org.apache.commons.mail.EmailException)

Example 4 with EmailMessage

use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.

the class DefaultAdminCredentialsVerifierNotificationTemplateTest method format_notification.

@Test
public void format_notification() {
    Notification notification = new Notification(DefaultAdminCredentialsVerifierNotification.TYPE);
    EmailMessage emailMessage = underTest.format(notification);
    assertThat(emailMessage.getSubject()).isEqualTo("Default Administrator credentials are still used");
    assertThat(emailMessage.getMessage()).isEqualTo("Hello,\n\n" + "Your SonarQube instance is still using default administrator credentials.\n" + "Make sure to change the password for the 'admin' account or deactivate this account.");
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 5 with EmailMessage

use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.

the class QGChangeEmailTemplateTest method shouldFormatNewAlertWithThresholdProperlyFormatted.

@UseDataProvider("alertTextAndFormattedText")
@Test
public void shouldFormatNewAlertWithThresholdProperlyFormatted(String alertText, String expectedFormattedAlertText) {
    Notification notification = createNotification("Failed", alertText, "ERROR", "true");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Version: V1-SNAP\n" + "Quality gate status: Failed\n" + "\n" + "New quality gate threshold: " + expectedFormattedAlertText + "\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

EmailMessage (org.sonar.server.issue.notification.EmailMessage)32 Test (org.junit.Test)27 Notification (org.sonar.api.notifications.Notification)13 CheckForNull (javax.annotation.CheckForNull)3 MimeMessage (javax.mail.internet.MimeMessage)3 WiserMessage (org.subethamail.wiser.WiserMessage)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Date (java.util.Date)2 EmailException (org.apache.commons.mail.EmailException)2 DateUtils.formatDate (org.sonar.api.utils.DateUtils.formatDate)2 EmailTemplate (org.sonar.server.issue.notification.EmailTemplate)2 EmailDeliveryRequest (org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1