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);
}
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());
}
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;
}
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();
}
}
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));
}
Aggregations