Search in sources :

Example 91 with SimpleMailMessage

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

the class MailSendingMessageHandlerTests method textMessage.

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

Example 92 with SimpleMailMessage

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

the class MailSendingMessageHandlerTests method mailHeaders.

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

Example 93 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project otter by alibaba.

the class DefaultAlarmService method doSend.

public void doSend(AlarmMessage data) throws Exception {
    // 只发送纯文本
    SimpleMailMessage mail = new SimpleMailMessage();
    mail.setFrom(username);
    // 主题
    mail.setSubject(TITLE);
    // 邮件内容
    mail.setText(data.getMessage());
    String[] receiveKeys = StringUtils.split(StringUtils.replace(data.getReceiveKey(), ";", ","), ",");
    SystemParameter systemParameter = systemParameterService.find();
    List<String> mailAddress = new ArrayList<String>();
    for (String receiveKey : receiveKeys) {
        String receiver = convertToReceiver(systemParameter, receiveKey);
        String[] strs = StringUtils.split(StringUtils.replace(receiver, ";", ","), ",");
        for (String str : strs) {
            if (isMail(str)) {
                if (str != null) {
                    mailAddress.add(str);
                }
            } else if (isSms(str)) {
            // do nothing
            }
        }
    }
    if (!mailAddress.isEmpty()) {
        mail.setTo(mailAddress.toArray(new String[mailAddress.size()]));
        doSendMail(mail);
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) ArrayList(java.util.ArrayList) SystemParameter(com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)

Example 94 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project paascloud-master by paascloud.

the class MailEntity method createSimpleMailMessage.

/**
 * Create simple mail message simple mail message.
 *
 * @param subject the subject
 * @param text    the text
 * @param to      the to
 *
 * @return the simple mail message
 */
public static SimpleMailMessage createSimpleMailMessage(String subject, String text, Set<String> to) {
    log.info("参数异常, 邮件信息不完整 subject={}, text={}, to={}", subject, text, to);
    Preconditions.checkArgument(!PubUtils.isNull(subject, text, to), "参数异常, 邮件信息不完整");
    String[] toArray = setToArray(to);
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(text);
    simpleMailMessage.setTo(toArray);
    return simpleMailMessage;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 95 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project oc-explorer by devgateway.

the class SendEmailService method sendEmail.

public void sendEmail(final String subject, final String text, final String to) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(to);
    msg.setFrom("support@developmentgateway.org");
    msg.setSubject(subject);
    msg.setText(text);
    try {
        LOGGER.info("Sending email " + msg);
        javaMailSenderImpl.send(msg);
    } catch (MailException e) {
        e.printStackTrace();
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException)

Aggregations

SimpleMailMessage (org.springframework.mail.SimpleMailMessage)106 MailException (org.springframework.mail.MailException)17 Test (org.junit.Test)13 Test (org.testng.annotations.Test)7 Test (org.junit.jupiter.api.Test)6 User (org.molgenis.data.security.auth.User)5 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)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 MailSendException (org.springframework.mail.MailSendException)4 InternetAddress (jakarta.mail.internet.InternetAddress)3 MimeMessage (jakarta.mail.internet.MimeMessage)3 Date (java.util.Date)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