Search in sources :

Example 11 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project webofneeds by researchstudio-sat.

the class WonMailSenderTest method sendTextMessage.

@Test
public void sendTextMessage() throws MessagingException {
    SimpleMailMessage message = new SimpleMailMessage();
    // replace sender specified in mail-sender.xml with the test sender
    message.setFrom("test@sender.com");
    wonEmailSender.sendTextMessage("test@receiver.com", "test subject", "test message");
    Message[] messages = testSmtp.getReceivedMessages();
    Assert.assertTrue(messages.length == 1);
    Assert.assertEquals("test subject", messages[0].getSubject());
    String body = GreenMailUtil.getBody(messages[0]).replaceAll("=\r?\n", "");
    Assert.assertEquals("test message", body);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Message(javax.mail.Message) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 12 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project ocvn by devgateway.

the class SendEmailService method sendEmailResetPassword.

/**
     * Send a reset password email. This is UNSAFE because passwords are sent in clear text.
     * Nevertheless some customers will ask for these emails to be sent, so ...
     * @param person
     * @param newPassword
     */
public void sendEmailResetPassword(final Person person, final String newPassword) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(person.getEmail());
    msg.setFrom("support@developmentgateway.org");
    msg.setSubject("Recover your password");
    msg.setText("Dear " + person.getFirstName() + " " + person.getLastName() + ",\n\n" + "These are your new login credentials for E-Procurement Toolkit.\n\n" + "Username: " + person.getUsername() + "\n" + "Password: " + newPassword + "\n\n" + "At login, you will be prompted to change your password to one of your choice.\n\n" + "Thank you,\n" + "DG Team");
    try {
        javaMailSenderImpl.send(msg);
    } catch (MailException e) {
        e.printStackTrace();
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException)

Example 13 with SimpleMailMessage

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

the class OptSendMailServiceImpl method sendSimpleMail.

@Override
public int sendSimpleMail(String subject, String text, Set<String> to) {
    log.info("sendSimpleMail - 发送简单邮件. subject={}, text={}, to={}", subject, text, to);
    int result = 1;
    try {
        SimpleMailMessage message = MailEntity.createSimpleMailMessage(subject, text, to);
        message.setFrom(from);
        taskExecutor.execute(() -> mailSender.send(message));
    } catch (Exception e) {
        log.info("sendSimpleMail [FAIL] ex={}", e.getMessage(), e);
        result = 0;
    }
    return result;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) TemplateException(freemarker.template.TemplateException) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) OpcBizException(com.paascloud.provider.exceptions.OpcBizException)

Example 14 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project webapp by elimu-ai.

the class Mailer method sendPlainText.

public static void sendPlainText(String to, String cc, String from, String subject, String text) {
    logger.info("sendPlainText");
    if (to.contains(",")) {
        to = to.replace(",", "");
    }
    if (to.contains(":")) {
        to = to.replace(":", "");
    }
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setTo(to);
    if (StringUtils.isNotBlank(cc)) {
        simpleMailMessage.setCc(cc);
    }
    simpleMailMessage.setBcc(ADMIN_EMAIL);
    simpleMailMessage.setFrom(from);
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(text);
    JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
    String smtpHost = ConfigHelper.getProperty("smtp.host");
    javaMailSenderImpl.setHost(smtpHost);
    logger.info("Sending e-mail to " + simpleMailMessage.getTo()[0] + " with subject \"" + simpleMailMessage.getSubject() + "\"...");
    logger.info("Text: " + simpleMailMessage.getText());
    if (EnvironmentContextLoaderListener.env != Environment.DEV) {
        javaMailSenderImpl.send(simpleMailMessage);
    }
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 15 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project microservices by pwillhan.

the class MailService method sendGenericMail.

public void sendGenericMail(String email, String subject, String body) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(email);
    msg.setFrom(env.getProperty("com.cassandrawebtrader.mail.from"));
    msg.setSubject(subject);
    msg.setText(body);
    try {
        mailSender.send(msg);
        logger.info(msg.toString());
    } catch (MailException e) {
        logger.error(e.getMessage());
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException)

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