Search in sources :

Example 36 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project spring-integration by spring-projects.

the class MailSendingMessageHandlerTests method simpleMailMessageOverrideWithHeaders.

@Test
public void simpleMailMessageOverrideWithHeaders() {
    SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
    mailMessage.getTo();
    this.handler.handleMessage(MessageBuilder.withPayload(mailMessage).setHeader(MailHeaders.TO, new String[] { "foo@bar.bam" }).build());
    assertEquals("only one simple message must be sent", 1, mailSender.getSentSimpleMailMessages().size());
    SimpleMailMessage sentMessage = mailSender.getSentSimpleMailMessages().get(0);
    assertTrue(sentMessage.getTo()[0].equals("foo@bar.bam"));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.junit.Test)

Example 37 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project spring-integration by spring-projects.

the class MailSendingMessageHandlerTests method simpleMailMessage.

@Test
public void simpleMailMessage() {
    SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
    String[] toHeaders = mailMessage.getTo();
    this.handler.handleMessage(MessageBuilder.withPayload(mailMessage).build());
    assertEquals("only one simple message must be sent", 1, mailSender.getSentSimpleMailMessages().size());
    SimpleMailMessage sentMessage = mailSender.getSentSimpleMailMessages().get(0);
    assertTrue(sentMessage.getTo().equals(toHeaders));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.junit.Test)

Example 38 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project onebusaway-application-modules by camsys.

the class ForgotPasswordAction method getMessage.

private SimpleMailMessage getMessage() {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(username);
    msg.setSubject(EMAIL_SUBJECT);
    String tempPass = _passwordService.getTemporaryPasswordForUser(username);
    msg.setText(getEmailBody(tempPass));
    return msg;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 39 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project Spring-Family by Sierou-Java.

the class MainServiceImpl method sendEmail.

/**
 * 发送Email服务
 *
 * @param content  内容
 * @param to       接受者
 * @param subject  主题
 * @return
 */
@Override
public Boolean sendEmail(String content, String to, String subject) {
    Boolean flag = false;
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    try {
        mailSender.send(message);
        flag = true;
        logger.info("简单邮件已经发送。");
    } catch (Exception e) {
        logger.error("发送简单邮件时发生异常!", e);
    }
    return flag;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MessagingException(javax.mail.MessagingException)

Example 40 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project cia by Hack23.

the class EmailServiceImpl method sendEmail.

@Override
public void sendEmail(final String toEmail, final String subject, final String content) {
    final ApplicationConfiguration sendEmail = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SEND_EMAILS, SEND_EMAIL, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SEND_EMAIL, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SEND_EMAIL, "false");
    final ApplicationConfiguration fromEmail = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_FROM_EMAIL, FROM_EMAIL, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SEND_EMAIL, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_FROM_EMAIL, "admin@hack23.com");
    final JavaMailSender javaMailSender = getMailSender();
    final SimpleMailMessage emailMessage = new SimpleMailMessage();
    emailMessage.setFrom(fromEmail.getPropertyValue());
    emailMessage.setTo(toEmail);
    emailMessage.setText(content);
    emailMessage.setSubject(subject);
    if ("true".equalsIgnoreCase(sendEmail.getPropertyValue())) {
        LOGGER.info("Sending email:{}", emailMessage);
        javaMailSender.send(emailMessage);
    } else {
        LOGGER.info("Email sending disabled, do not send email:{}", emailMessage);
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)

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