Search in sources :

Example 31 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project tutorials by eugenp.

the class SpringBootMailIntegrationTest method composeEmailMessage.

private SimpleMailMessage composeEmailMessage() {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setTo(userTo);
    mailMessage.setReplyTo(userFrom);
    mailMessage.setFrom(userFrom);
    mailMessage.setSubject(subject);
    mailMessage.setText(textMail);
    return mailMessage;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 32 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project tutorials by eugenp.

the class AppConfig method templateSimpleMessage.

@Bean
public SimpleMailMessage templateSimpleMessage() {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setText("This is the test email template for your email:\n%s\n");
    return message;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Bean(org.springframework.context.annotation.Bean)

Example 33 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project tutorials by eugenp.

the class EmailServiceImpl method sendSimpleMessage.

public void sendSimpleMessage(String to, String subject, String text) {
    try {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);
        message.setSubject(subject);
        message.setText(text);
        emailSender.send(message);
    } catch (MailException exception) {
        exception.printStackTrace();
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException)

Example 34 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project spring-boot-examples by ityouknow.

the class MailServiceImpl method sendSimpleMail.

/**
 * 发送文本邮件
 * @param to
 * @param subject
 * @param content
 */
@Override
public void sendSimpleMail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    try {
        mailSender.send(message);
        logger.info("简单邮件已经发送。");
    } catch (Exception e) {
        logger.error("发送简单邮件时发生异常!", e);
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MessagingException(javax.mail.MessagingException)

Example 35 with SimpleMailMessage

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

the class MailSendingMessageHandlerContextTests method stringMessagesWithConfiguration.

@Test
public void stringMessagesWithConfiguration() {
    this.handler.handleMessage(MailTestsHelper.createIntegrationMessage());
    SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
    assertEquals("no mime message should have been sent", 0, this.mailSender.getSentMimeMessages().size());
    assertEquals("only one simple message must be sent", 1, this.mailSender.getSentSimpleMailMessages().size());
    assertEquals("message content different from expected", mailMessage, this.mailSender.getSentSimpleMailMessages().get(0));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.junit.Test)

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