Search in sources :

Example 41 with SimpleMailMessage

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("テストメッセージテキスト");
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMessage(javax.mail.internet.MimeMessage) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 42 with SimpleMailMessage

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);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 43 with SimpleMailMessage

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);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 44 with SimpleMailMessage

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);
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) NoSuchMessageException(org.springframework.context.NoSuchMessageException)

Example 45 with SimpleMailMessage

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);
        }
    }
}
Also used : User(gemma.gsec.model.User) SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Aggregations

SimpleMailMessage (org.springframework.mail.SimpleMailMessage)103 MailException (org.springframework.mail.MailException)16 Test (org.junit.Test)12 Test (org.testng.annotations.Test)7 Test (org.junit.jupiter.api.Test)6 User (org.molgenis.data.security.auth.User)5 IOException (java.io.IOException)4 MessagingException (javax.mail.MessagingException)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 InternetAddress (jakarta.mail.internet.InternetAddress)3 MimeMessage (jakarta.mail.internet.MimeMessage)3 Date (java.util.Date)3 MimeMessage (javax.mail.internet.MimeMessage)3 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)3 MolgenisUserException (org.molgenis.security.user.MolgenisUserException)3 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 User (fr.codechill.spring.model.User)2 User (gemma.gsec.model.User)2