Search in sources :

Example 61 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project spring-boot-admin by codecentric.

the class MailNotifierTest method test_onApplicationEvent.

@Test
public void test_onApplicationEvent() {
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo.ofUp()));
    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setTo(new String[] { "foo@bar.com" });
    expected.setCc(new String[] { "bar@foo.com" });
    expected.setFrom("SBA <no-reply@example.com>");
    expected.setText("App (-id-)\nstatus changed from DOWN to UP\n\nhttp://health");
    expected.setSubject("-id- is UP");
    verify(sender).send(eq(expected));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 62 with SimpleMailMessage

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

the class JavaMailSenderTests method testJavaMailSenderWithSimpleMessages.

public void testJavaMailSenderWithSimpleMessages() throws MessagingException, IOException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPassword("password");
    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("he@mail.org");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("she@mail.org");
    sender.send(simpleMessage1, simpleMessage2);
    assertEquals("host", sender.transport.getConnectedHost());
    assertEquals("username", sender.transport.getConnectedUsername());
    assertEquals("password", sender.transport.getConnectedPassword());
    assertTrue(sender.transport.isCloseCalled());
    assertEquals(2, sender.transport.getSentMessages().size());
    MimeMessage sentMessage1 = sender.transport.getSentMessage(0);
    List<Address> tos1 = Arrays.asList(sentMessage1.getRecipients(Message.RecipientType.TO));
    assertEquals(1, tos1.size());
    assertEquals("he@mail.org", ((InternetAddress) tos1.get(0)).getAddress());
    MimeMessage sentMessage2 = sender.transport.getSentMessage(1);
    List<Address> tos2 = Arrays.asList(sentMessage2.getRecipients(Message.RecipientType.TO));
    assertEquals(1, tos2.size());
    assertEquals("she@mail.org", ((InternetAddress) tos2.get(0)).getAddress());
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage)

Example 63 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project transporter by wang4ever.

the class MailSenderService method sendEmailMessageOfSimpleText.

/**
 * 发送简单文本Email消息
 *
 * @param emailMsg
 */
public void sendEmailMessageOfSimpleText(MailMessage emailMsg, Date date) {
    SimpleMailMessage simpleTextMessage = new SimpleMailMessage();
    simpleTextMessage.setFrom(sender);
    simpleTextMessage.setTo(emailMsg.getReceivers());
    if (emailMsg.getBcc() != null && emailMsg.getBcc().length > 0)
        simpleTextMessage.setBcc(emailMsg.getBcc());
    if (emailMsg.getCc() != null && emailMsg.getCc().length > 0)
        simpleTextMessage.setCc(emailMsg.getCc());
    simpleTextMessage.setText(emailMsg.getEmailContent());
    if (null == date)
        date = new Date();
    simpleTextMessage.setSentDate(date);
    javaMailSender.send(simpleTextMessage);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Date(java.util.Date)

Example 64 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project code-chill by CodeChillAlluna.

the class UserController method updateEmailError.

// Method sending an error message for the former email adress
public boolean updateEmailError(String email) {
    User user = urepo.findByEmail(email);
    if (user != null) {
        SimpleMailMessage infoUpdateFail = new SimpleMailMessage();
        infoUpdateFail.setFrom(SENDFROM);
        infoUpdateFail.setTo(user.getEmail());
        infoUpdateFail.setSubject("Suspicious access to your account");
        infoUpdateFail.setText("We have registered a suspicious activity on your acccount");
        mailSender.send(infoUpdateFail);
        return true;
    }
    return false;
}
Also used : User(fr.codechill.spring.model.User) SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 65 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project Logos_Materials_October_2017 by VolodymyrZavada.

the class EmailServiceImpl method sendMessage.

@Override
public void sendMessage(Mail mail) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(mail.getFrom());
    message.setTo(mail.getTo());
    message.setSubject(mail.getSubject());
    message.setText(mail.getContent());
    mailSender.send(message);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

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