use of org.springframework.mail.SimpleMailMessage in project sandbox by irof.
the class SpringMailTest method test.
@Test
public void test() throws Exception {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("from-test@example.com");
message.setTo("to-1@example.com", "to-2@example.com");
message.setCc("cc-1@example.com");
message.setSubject("テストメッセージサブジェクト");
message.setText("テストメッセージテキスト");
sender.send(message);
MimeMessage[] receivedMessages = greenMailRule.getReceivedMessages();
// 宛先が3つなので
assertThat(receivedMessages).hasSize(3);
MimeMessage receivedMessage = receivedMessages[0];
assertThat(receivedMessage.getSubject()).isEqualTo("テストメッセージサブジェクト");
assertThat(receivedMessage.getContent()).isEqualTo("テストメッセージテキスト");
}
use of org.springframework.mail.SimpleMailMessage in project Gemma by PavlidisLab.
the class BaseFormController method sendEmail.
/**
* Convenience message to send messages to users
*/
protected void sendEmail(User user, String templateName, Map<String, Object> model) {
if (StringUtils.isBlank(user.getEmail())) {
log.warn("Could not send email to " + user + ", no email address");
}
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(user.getFullName() + "<" + user.getEmail() + ">");
mailEngine.sendMessage(message, templateName, model);
}
use of org.springframework.mail.SimpleMailMessage in project Gemma by PavlidisLab.
the class BaseFormController method sendEmail.
/**
* Convenience message to send messages to users
*/
protected void sendEmail(User user, String msg) {
if (StringUtils.isBlank(user.getEmail())) {
log.warn("Could not send email to " + user + ", no email address");
}
log.debug("sending e-mail to user [" + user.getEmail() + "]...");
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(user.getFullName() + "<" + user.getEmail() + ">");
mailEngine.send(message);
}
use of org.springframework.mail.SimpleMailMessage in project Gemma by PavlidisLab.
the class BaseController method sendConfirmationEmail.
protected void sendConfirmationEmail(HttpServletRequest request, String token, String username, String email, Map<String, Object> model, String templateName) {
try {
model.put("username", username);
model.put("confirmLink", Settings.getBaseUrl() + "confirmRegistration.html?key=" + token + "&username=" + username);
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setFrom(Settings.getAdminEmailAddress());
mailMessage.setSubject(getText("signup.email.subject", request.getLocale()));
mailMessage.setTo(username + "<" + email + ">");
mailEngine.sendMessage(mailMessage, templateName, model);
} catch (Exception e) {
log.error("Couldn't send email to " + email, e);
}
}
use of org.springframework.mail.SimpleMailMessage in project Gemma by PavlidisLab.
the class MailUtilsImpl method sendTaskCompletedNotificationEmail.
@Override
public void sendTaskCompletedNotificationEmail(EmailNotificationContext emailNotificationContext, TaskResult taskResult) {
String taskId = emailNotificationContext.getTaskId();
String submitter = emailNotificationContext.getSubmitter();
String taskName = emailNotificationContext.getTaskName();
if (StringUtils.isNotBlank(submitter)) {
User user = userService.findByUserName(submitter);
assert user != null;
String emailAddress = user.getEmail();
if (emailAddress != null) {
MailUtilsImpl.log.info("Sending email notification to " + emailAddress);
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(emailAddress);
msg.setFrom(Settings.getAdminEmailAddress());
msg.setSubject("Gemma task completed");
String logs = "";
if (taskResult.getException() != null) {
logs += "Task failed with :\n";
logs += taskResult.getException().getMessage();
}
msg.setText("A job you started on Gemma is completed (taskId=" + taskId + ", " + taskName + ")\n\n" + logs + "\n");
mailEngine.send(msg);
}
}
}
Aggregations