Search in sources :

Example 26 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project spring-boot by Linda-Tan.

the class EmailService method send.

/**
 * 发送邮件
 * @param email
 */
public void send(@Valid Email email) {
    log.info("发送邮件:{}", email.getContent());
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(fromUser);
    message.setTo(email.getEmail());
    message.setSubject(email.getSubject());
    message.setText(email.getContent());
    mailSender.send(message);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 27 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project lumberjack by fn-ctional.

the class AuthenticationController method resendRegistrationToken.

@GetMapping(value = "/user/resendRegistrationToken")
@ResponseBody
public ModelAndView resendRegistrationToken(HttpServletRequest request, @RequestParam("token") String existingToken, Model model) {
    try {
        VerificationToken newToken = userService.generateNewVerificationToken(existingToken);
        AdminUser user = userService.getUser(newToken.getToken());
        String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
        SimpleMailMessage email = constructResendVerificationTokenEmail(appUrl, request.getLocale(), newToken, user);
        mailSender.send(email);
        model.addAttribute("messageType", "Successfully resent!");
        model.addAttribute("messageString", "Please check your inbox!");
    } catch (SQLException e) {
        model.addAttribute("messageType", "Database Error!");
        model.addAttribute("messageString", "Please try again.");
    } catch (Exception e) {
        model.addAttribute("messageType", "Unknown Server Error!");
        model.addAttribute("messageString", "Please try again.");
    }
    return new ModelAndView("message", "user", hashCode());
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) SQLException(java.sql.SQLException) ModelAndView(org.springframework.web.servlet.ModelAndView) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) EmailNotPermittedException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) SQLException(java.sql.SQLException) EmailExistsException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException)

Example 28 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project lumberjack by fn-ctional.

the class AuthenticationController method constructResendVerificationTokenEmail.

private SimpleMailMessage constructResendVerificationTokenEmail(String contextPath, Locale locale, VerificationToken newToken, AdminUser adminUser) {
    String confirmationUrl = contextPath + "/regitrationConfirm.html?token=" + newToken.getToken();
    String message = "please resend please";
    SimpleMailMessage email = new SimpleMailMessage();
    email.setSubject("Resend Registration Token");
    email.setText(message + " rn" + confirmationUrl);
    email.setFrom(environment.getProperty("support.email"));
    email.setTo(adminUser.getEmail());
    return email;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 29 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project ocvn 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)

Example 30 with SimpleMailMessage

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

the class SpringBootMailIntegrationTest method givenMail_whenSendAndReceived_thenCorrect.

@Test
public void givenMail_whenSendAndReceived_thenCorrect() throws Exception {
    SimpleMailMessage message = composeEmailMessage();
    javaMailSender.send(message);
    List<WiserMessage> messages = wiser.getMessages();
    assertThat(messages, hasSize(1));
    WiserMessage wiserMessage = messages.get(0);
    assertEquals(userFrom, wiserMessage.getEnvelopeSender());
    assertEquals(userTo, wiserMessage.getEnvelopeReceiver());
    assertEquals(subject, getSubject(wiserMessage));
    assertEquals(textMail, getMessage(wiserMessage));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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