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));
}
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;
}
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;
}
}
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.");
}
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"));
}
Aggregations