use of org.springframework.mail.SimpleMailMessage in project perun by CESNET.
the class Utils method sendPasswordResetEmail.
/**
* Sends email with link to non-authz password reset GUI where user
* can reset forgotten password
*
* @param user user to send notification for
* @param email user's email to send notification to
* @param namespace namespace to reset password in
* @param url base URL of Perun instance
* @param id ID of pwd reset request
* @throws InternalErrorException
*/
public static void sendPasswordResetEmail(User user, String email, String namespace, String url, int id) throws InternalErrorException {
// create mail sender
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("localhost");
// create message
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(email);
message.setFrom(BeansUtils.getCoreConfig().getMailchangeBackupFrom());
String instanceName = BeansUtils.getCoreConfig().getInstanceName();
message.setSubject("[" + instanceName + "] Password reset in namespace: " + namespace);
// get validation link params
String i = cipherInput(String.valueOf(user.getId()), false);
String m = cipherInput(String.valueOf(id), false);
try {
URL urlObject = new URL(url);
StringBuilder link = new StringBuilder();
link.append(urlObject.getProtocol());
link.append("://");
link.append(urlObject.getHost());
// reset link uses non-authz
link.append("/non/pwd-reset/");
link.append("?i=");
link.append(URLEncoder.encode(i, "UTF-8"));
link.append("&m=");
link.append(URLEncoder.encode(m, "UTF-8"));
// Build message
String text = "Dear " + user.getDisplayName() + ",\n\nWe've received request to reset your password in namespace \"" + namespace + "\"." + "\n\nPlease visit the link below, where you can set new password:\n\n" + link + "\n\n" + "Message is automatically generated." + "\n----------------------------------------------------------------" + "\nPerun - Identity & Access Management System";
message.setText(text);
mailSender.send(message);
} catch (UnsupportedEncodingException ex) {
throw new InternalErrorException("Unable to encode URL for password reset.", ex);
} catch (MalformedURLException ex) {
throw new InternalErrorException("Not valid URL of running Perun instance.", ex);
}
}
use of org.springframework.mail.SimpleMailMessage in project Gargoyle by callakrsos.
the class Mailer method sendMail.
public void sendMail(SenderMailInfo mailSenderInfo, Mail mail, VelocityContext velocityContext) throws Exception {
if (this.mailUseYn != null) {
if ("N".equals(this.mailUseYn)) {
throw new Exception("Mail Serivce's configuration is not set useYn Y ");
}
}
String _encoding = MailConst.MAILER_DEFAULT_ENCODING;
SimpleMailMessage message = new SimpleMailMessage();
if (mail.getMailFrom() != null) {
message.setFrom(mail.getMailFrom());
} else if (ValueUtil.isNotEmpty(mailFrom)) {
message.setFrom(mailFrom);
} else {
String fromAddr = ResourceLoader.getInstance().get("mail.from.address");
message.setFrom(fromAddr);
}
message.setTo(mail.getMailTo());
if (mail.getMailSubject() != null) {
message.setSubject(mail.getMailSubject());
} else {
message.setSubject(this.mailTitle);
}
if (encoding != null)
_encoding = encoding;
if (mailSenderInfo != null) {
String sendUserId = mailSenderInfo.getSendUserId();
String sendUserPassword = mailSenderInfo.getSendUserPassword();
if (ValueUtil.isEmpty(sendUserId) || ValueUtil.isEmpty(sendUserPassword)) {
throw new IllegalArgumentException("user id or password is empty...");
}
mailSender.setUsername(sendUserId);
mailSender.setPassword(sendUserPassword);
}
// MailUtil.getTemplate(velocityEngine,mail.getTemplateName(),this.mailTemplate);
Template template = MailUtil.getTemplateFromFile(mailTemplate);
template.setEncoding(_encoding);
StringWriter stringWriter = new StringWriter();
template.merge(velocityContext, stringWriter);
message.setText(stringWriter.toString());
// MimeMessage createMimeMessage = mailSender.createMimeMessage();
// createMimeMessage.addHeader("text/html", stringWriter.toString());
mailSender.send(message);
}
use of org.springframework.mail.SimpleMailMessage in project fake-smtp-server by gessnerfl.
the class TestDataCreator method createEmail.
private static void createEmail(int i) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo("receiver@exmaple.com");
message.setFrom("sender@example.com");
message.setSubject("Test-Mail " + i);
message.setText("This is the test mail number " + i);
getEmailSender().send(message);
}
use of org.springframework.mail.SimpleMailMessage in project spring-thymeleaf-simplefinance by heitkergm.
the class Application method sendStartupEmail.
private static void sendStartupEmail(final ApplicationContext ctx) {
MailSender mailer = ctx.getBean(MailSender.class);
SimpleMailMessage msg = new SimpleMailMessage();
String envProp = System.getenv("MAIL_TO");
String recipient;
recipient = envProp != null ? envProp : ctx.getMessage("mail.to", new Object[] {}, Locale.getDefault());
msg.setFrom(ctx.getMessage("mail.sender", new Object[] {}, Locale.getDefault()));
msg.setTo(recipient);
msg.setSubject(ctx.getMessage("mail.subject", new Object[] {}, Locale.getDefault()));
msg.setText(ctx.getMessage("mail.upmsg", new Object[] {}, Locale.getDefault()));
mailer.send(msg);
}
use of org.springframework.mail.SimpleMailMessage in project bitcampSCOpen2017 by ryuyj.
the class SimpleRegistrationNotifier method sendMail.
public void sendMail(Member member) {
// 보내는 정보를 simpleMailMessage 객체에 담는다.
SimpleMailMessage message = new SimpleMailMessage();
message.setSubject("[회원가입안내]" + member.getMember_name() + "님 회원가입을 축하합니다.");
message.setFrom("jjy905@gamil.com");
message.setText("회원가입 성공");
message.setTo(member.getMember_id());
mailSender.send(message);
}
Aggregations