use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.
the class QueryServiceImpl method sendEmail.
private void sendEmail(String to, String subject, String body, Boolean htmlEmail) throws Exception {
try {
JavaMailSenderImpl mailSender = (JavaMailSenderImpl) appContext.getBean("mailSender");
Properties javaMailProperties = mailSender.getJavaMailProperties();
if (null != javaMailProperties) {
if (javaMailProperties.get("mail.smtp.localhost") == null || ((String) javaMailProperties.get("mail.smtp.localhost")).equalsIgnoreCase("")) {
javaMailProperties.put("mail.smtp.localhost", "localhost");
}
}
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, htmlEmail);
helper.setFrom(EmailEngine.getAdminEmail());
helper.setTo(processMultipleImailAddresses(to.trim()));
helper.setSubject(subject);
helper.setText(body, true);
mailSender.send(mimeMessage);
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
logger.error("Email could not be sent on {} due to: {}", new Date(), me.getMessage());
}
}
use of org.springframework.mail.MailException in project webofneeds by researchstudio-sat.
the class WonMailSender method sendTextMessage.
public void sendTextMessage(String toEmail, String subject, String text) {
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
msg.setSubject(subject);
msg.setTo(toEmail);
msg.setText(text);
try {
mailSender.send(msg);
} catch (MailException ex) {
logger.warn(ex.getMessage());
}
}
use of org.springframework.mail.MailException in project coprhd-controller by CoprHD.
the class MailHelper method sendMailMessage.
public void sendMailMessage(String to, String subject, String html) {
try {
JavaMailSender mailSender = getMailSender();
if (mailSender != null) {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false, "utf-8");
helper.setText(html, true);
String[] addresses = StringUtils.split(to, ",");
for (String address : addresses) {
address = StringUtils.trimToNull(address);
if (address != null) {
helper.addTo(address);
}
}
helper.setSubject(subject);
mailSender.send(mimeMessage);
} else {
log.warn("Unable to send notification email. Email settings not configured.");
}
} catch (MailException | MessagingException ex) {
String message = String.format("Failed to notify user by email");
log.error(message, ex);
throw APIException.internalServerErrors.genericApisvcError(message, ex);
}
}
use of org.springframework.mail.MailException 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();
}
}
use of org.springframework.mail.MailException in project judge by zjnu-acm.
the class ResetPasswordController method doPost.
@PostMapping("/resetPassword")
public void doPost(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "verify", required = false) String verify, @RequestParam(value = "username", required = false) String username, Locale locale) throws IOException {
response.setContentType("text/javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(false);
String word = null;
if (session != null) {
word = (String) session.getAttribute("word");
session.removeAttribute("word");
}
if (word == null || !word.equalsIgnoreCase(verify)) {
out.print("alert('验证码错误');");
return;
}
User user = userMapper.findOne(username);
if (user == null) {
out.print("alert('用户不存在');");
return;
}
String email = user.getEmail();
if (email == null || !email.toLowerCase().matches(ValueCheck.EMAIL_PATTERN)) {
out.print("alert('该用户未设置邮箱或邮箱格式不对,如需重置密码,请联系管理员!');");
return;
}
try {
String vc = resetPasswordService.getOrCreate(user.getId());
String url = getPath(request, "/resetPassword.html?vc=", vc + "&u=", user.getId());
String title = systemService.getResetPasswordTitle();
Map<String, Object> map = ImmutableMap.of("url", url, "title", Objects.toString(title, ""));
String content = templateEngine.process("users/password", new Context(locale, map));
emailService.send(email, title, content);
} catch (MailException | MessagingException ex) {
log.error("fail to send email", ex);
out.print("alert('邮件发送失败,请稍后再试')");
return;
}
out.print("alert('已经将邮件发送到" + user.getEmail() + ",请点击链接重设密码');");
}
Aggregations