use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.
the class IssueChangesEmailTemplate method format.
@Override
public EmailMessage format(Notification notif) {
if (!IssueChangeNotification.TYPE.equals(notif.getType())) {
return null;
}
StringBuilder sb = new StringBuilder();
appendHeader(notif, sb);
sb.append(NEW_LINE);
appendChanges(notif, sb);
sb.append(NEW_LINE);
appendFooter(sb, notif);
String projectName = notif.getFieldValue("projectName");
String issueKey = notif.getFieldValue("key");
String author = notif.getFieldValue("changeAuthor");
EmailMessage message = new EmailMessage().setMessageId("issue-changes/" + issueKey).setSubject(projectName + ", change on issue #" + issueKey).setMessage(sb.toString());
if (author != null) {
message.setFrom(getUserFullName(author));
}
return message;
}
use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.
the class AlertsEmailTemplate method format.
@Override
public EmailMessage format(Notification notification) {
if (!"alerts".equals(notification.getType())) {
return null;
}
// Retrieve useful values
String projectId = notification.getFieldValue("projectId");
String projectKey = notification.getFieldValue("projectKey");
String projectName = notification.getFieldValue("projectName");
String alertName = notification.getFieldValue("alertName");
String alertText = notification.getFieldValue("alertText");
String alertLevel = notification.getFieldValue("alertLevel");
boolean isNewAlert = Boolean.parseBoolean(notification.getFieldValue("isNewAlert"));
// Generate text
String subject = generateSubject(projectName, alertLevel, isNewAlert);
String messageBody = generateMessageBody(projectName, projectKey, alertName, alertText, isNewAlert);
// And finally return the email that will be sent
return new EmailMessage().setMessageId("alerts/" + projectId).setSubject(subject).setMessage(messageBody);
}
use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.
the class EmailNotificationChannel method deliver.
@Override
public void deliver(Notification notification, String username) {
User user = userFinder.findByLogin(username);
if (user == null || StringUtils.isBlank(user.email())) {
LOG.debug("User does not exist or has no email: {}", username);
return;
}
EmailMessage emailMessage = format(notification);
if (emailMessage != null) {
emailMessage.setTo(user.email());
deliver(emailMessage);
}
}
use of org.sonar.plugins.emailnotifications.api.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.setMessage(message);
send(emailMessage);
} catch (EmailException e) {
LOG.debug("Fail to send test email to: " + toAddress, e);
throw e;
}
}
use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.
the class NewIssuesEmailTemplateTest method message_id.
@Test
public void message_id() {
Notification notification = newNotification();
EmailMessage message = template.format(notification);
assertThat(message.getMessageId()).isEqualTo("new-issues/org.apache:struts");
}
Aggregations