List of usage examples for org.springframework.mail.javamail MimeMessageHelper setFrom
public void setFrom(String from) throws MessagingException
From source file:com.hmsinc.epicenter.webapp.PasswordResetController.java
/** * @param token// ww w. j a v a 2s .c om * @param url */ private void sendPasswordResetEmail(final PasswordResetToken token, final String url) { final MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(MimeMessage mimeMessage) throws Exception { final EpiCenterUser user = token.getUser(); String encoding = "UTF-8"; final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_RELATED, encoding); message.setTo(user.getEmailAddress()); message.setFrom(applicationProperties.getProperty("epicenter.mail.from")); message.setSubject(mailSubject); final Map<String, Object> model = new HashMap<String, Object>(); model.put("url", url); model.put("username", user.getUsername()); model.put("token", token.getToken()); message.setText(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, TEMPLATE_TEXT, model), VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, TEMPLATE_HTML, model)); } }; mailSender.send(preparator); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.article.AddArticleCommentController.java
private void sendNotification(String email, ArticleComment comment, HttpServletRequest request) throws MessagingException { String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + comment.getArticle().getArticleId(); //System.out.println(articleURL); String subject = messageSource.getMessage("articles.group.email.subscribtion.subject", new String[] { comment.getArticle().getTitle(), comment.getPerson().getUsername() }, RequestContextUtils.getLocale(request)); //System.out.println(subject); String emailBody = "<html><body>"; emailBody += "<p>" + messageSource.getMessage("articles.group.email.subscribtion.body.text.part1", new String[] { comment.getArticle().getTitle() }, RequestContextUtils.getLocale(request)) + ""; emailBody += " (<a href=\"" + articleURL + "\" target=\"_blank\">" + articleURL + "</a>)</p><br />"; emailBody += "<h3>Text:</h3> <p>" + comment.getText() + "</p><br />"; emailBody += "<p>" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part2", null, RequestContextUtils.getLocale(request)) + "</p>"; emailBody += "</body></html>"; //System.out.println(emailBody); log.debug("email body: " + emailBody); log.debug("Composing e-mail message"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setFrom(mailMessage.getFrom()); // message.setContent("text/html"); message.setTo(email);//from w w w . ja v a2 s.c o m //helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request))); message.setSubject(subject); message.setText(emailBody, true); try { log.debug("Sending e-mail" + message); log.debug("mailSender" + mailSender); log.debug("smtp " + mailSender.getHost()); mailSender.send(mimeMessage); log.debug("E-mail was sent"); } catch (MailException e) { log.error("E-mail was NOT sent"); log.error(e); } }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.article.AddArticleController.java
private void sendNotification(String email, Article article, HttpServletRequest request) throws MessagingException { String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + article.getArticleId(); //System.out.println(articleURL); String subject = messageSource.getMessage("articles.group.email.subscribtion.subject", new String[] { article.getTitle(), article.getPerson().getUsername() }, RequestContextUtils.getLocale(request)); //System.out.println(subject); String emailBody = "<html><body>"; emailBody += "<p>" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part1", new String[] { article.getTitle() }, RequestContextUtils.getLocale(request)) + ""; emailBody += " (<a href=\"" + articleURL + "\" target=\"_blank\">" + articleURL + "</a>)</p><br />"; emailBody += "<h3>" + article.getTitle() + "</h3> <p>" + article.getText() + "</p><br />"; emailBody += "<p>" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part2", null, RequestContextUtils.getLocale(request)) + "</p>"; emailBody += "</body></html>"; //System.out.println(emailBody); log.debug("email body: " + emailBody); log.debug("Composing e-mail message"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setFrom(mailMessage.getFrom()); // message.setContent("text/html"); message.setTo(email);//from w ww . jav a 2 s . c om //helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request))); message.setSubject(subject); message.setText(emailBody, true); try { log.debug("Sending e-mail" + message); log.debug("mailSender" + mailSender); log.debug("smtp " + mailSender.getHost()); mailSender.send(mimeMessage); log.debug("E-mail was sent"); } catch (MailException e) { log.error("E-mail was NOT sent"); log.error(e); } }
From source file:it.jugpadova.blo.ParticipantBo.java
/** * General participant mail sender// ww w .jav a 2s . co m * * @param participant * @param baseUrl * @param subject * @param oneWayCode * @param template */ private void sendEmail(final Participant participant, final String baseUrl, final String subject, final String template, final Resource attachment, final String attachmentName) { MimeMessagePreparator preparator = new MimeMessagePreparator() { @SuppressWarnings(value = "unchecked") public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true); message.setTo(participant.getEmail()); message.setFrom(conf.getConfirmationSenderEmailAddress()); message.setSubject(subject); Map model = new HashMap(); model.put("participant", participant); model.put("baseUrl", baseUrl); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template, model); message.setText(text, true); if (attachment != null) { message.addAttachment(attachmentName, attachment); } } }; this.mailSender.send(preparator); }
From source file:eu.trentorise.smartcampus.citizenportal.service.EmailService.java
public String sendMailWithAttachment(final String recipientName, final String recipientEmail, final String practice_id, final String position, final String score, final String phase, final String ef_period, final String ef_category, final String ef_tool, final String subject, final String attachmentFileName, final byte[] attachmentBytes, final String attachmentContentType, final Locale locale) throws MessagingException { // Prepare the evaluation context final Context ctx = new Context(locale); ctx.setVariable("name", recipientName); ctx.setVariable("practice_id", practice_id); ctx.setVariable("position", position); ctx.setVariable("score", score); ctx.setVariable("phase", phase); ctx.setVariable("ef_period", ef_period); ctx.setVariable("ef_category", ef_category); ctx.setVariable("ef_tool", ef_tool); ctx.setVariable("subscriptionDate", new Date()); //ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music")); ctx.setVariable("text", subject); // Prepare message using a Spring helper final MimeMessage mimeMessage = this.mailSender.createMimeMessage(); final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true /* multipart */, "UTF-8"); message.setSubject("Graduatoria Edilizia Abitativa"); //message.setFrom("thymeleaf@example.com"); message.setFrom("myweb.edilizia@comunitadellavallagarina.tn.it"); message.setTo(recipientEmail);// w w w.j a v a 2 s . c om // Create the HTML body using Thymeleaf final String htmlContent = this.templateEngine.process("email-withattachment.html", ctx); message.setText(htmlContent, true /* isHtml */); // Add the attachment final InputStreamSource attachmentSource = new ByteArrayResource(attachmentBytes); message.addAttachment(attachmentFileName, attachmentSource, attachmentContentType); // Send mail this.mailSender.send(mimeMessage); return recipientName + "OK"; }
From source file:org.topazproject.ambra.email.impl.FreemarkerTemplateMailer.java
/** * Mail the email formatted using the given templates * @param toEmailAddresses List of email addresses to which emails should be sent. White space delimited. * @param fromEmailAddress fromEmailAddress * @param subject subject of the email//from w ww . j av a2 s . c om * @param context context to set the values from for the template * @param textTemplateFilename textTemplateFilename * @param htmlTemplateFilename htmlTemplateFilename */ public void mail(final String toEmailAddresses, final String fromEmailAddress, final String subject, final Map<String, Object> context, final String textTemplateFilename, final String htmlTemplateFilename) { final StringTokenizer emailTokens = new StringTokenizer(toEmailAddresses); while (emailTokens.hasMoreTokens()) { final String toEmailAddress = emailTokens.nextToken(); final MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(final MimeMessage mimeMessage) throws MessagingException, IOException { final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, configuration.getDefaultEncoding()); message.setTo(new InternetAddress(toEmailAddress)); message.setFrom(new InternetAddress(fromEmailAddress, (String) context.get(USER_NAME_KEY))); message.setSubject(subject); // Create a "text" Multipart message final Multipart mp = createPartForMultipart(textTemplateFilename, context, "alternative", MIME_TYPE_TEXT_PLAIN + "; charset=" + configuration.getDefaultEncoding()); // Create a "HTML" Multipart message final Multipart htmlContent = createPartForMultipart(htmlTemplateFilename, context, "related", MIME_TYPE_TEXT_HTML + "; charset=" + configuration.getDefaultEncoding()); final BodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(htmlContent); mp.addBodyPart(htmlPart); mimeMessage.setContent(mp); } }; mailSender.send(preparator); if (log.isDebugEnabled()) { log.debug("Mail sent to:" + toEmailAddress); } } }
From source file:eu.trentorise.smartcampus.citizenportal.service.EmailService.java
public String sendMailVLClassification(final String period, final String mailDate, final String protocolCode, final String recipientName, final String recipientAddress, final String recipientCity, final String recipientPhone, final String recipientEmail, final String practice_id, final String position, final String score, final String determinationCode, final String determinationDate, final String alboDate, final String expirationDate, final String phase, final String ef_period, final String ef_category, final String ef_tool, final String classificationUrl, final String respName, final String subject, final Locale locale, final MailImage logoImage, final MailImage footerImage, final int type) throws MessagingException { // Prepare the evaluation context final Context ctx = new Context(locale); ctx.setVariable("imagelogoMyweb", logoImage.getImageName()); ctx.setVariable("mailDate", mailDate); ctx.setVariable("period", period); ctx.setVariable("protCode", protocolCode); ctx.setVariable("name", recipientName); ctx.setVariable("address", recipientAddress); ctx.setVariable("city", recipientCity); ctx.setVariable("phone", recipientPhone); ctx.setVariable("detCode", determinationCode); ctx.setVariable("detDate", determinationDate); ctx.setVariable("alboDate", alboDate); ctx.setVariable("expDate", expirationDate); ctx.setVariable("practice_id", practice_id); ctx.setVariable("position", position); ctx.setVariable("score", score); ctx.setVariable("phase", phase); ctx.setVariable("ef_period", ef_period); ctx.setVariable("ef_category", ef_category); ctx.setVariable("ef_tool", ef_tool); ctx.setVariable("classification_url", classificationUrl); ctx.setVariable("respName", respName); ctx.setVariable("subscriptionDate", new Date()); //ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music")); ctx.setVariable("text", subject); ctx.setVariable("imagefooterVallag", footerImage.getImageName()); // Prepare message using a Spring helper final MimeMessage mimeMessage = this.mailSender.createMimeMessage(); final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true /* multipart */, "UTF-8"); message.setSubject("Graduatoria Edilizia Abitativa"); //message.setFrom("thymeleaf@example.com"); message.setFrom("myweb.edilizia@comunitadellavallagarina.tn.it"); //message.setFrom("myweb-graduatoria@smartcommunitylab.it"); message.setTo(recipientEmail);/* ww w . j a va 2s.c o m*/ // Create the HTML body using Thymeleaf if (type == 1) { final String htmlContent = this.templateEngine.process("email-vallagarina.html", ctx); message.setText(htmlContent, true /* isHtml */); } else { final String htmlContent = this.templateEngine.process("email-vallagarina-final.html", ctx); message.setText(htmlContent, true /* isHtml */); } // Add the inline titles image, referenced from the HTML code as "cid:${imageResourceName}" final InputStreamSource imageLogo = new ByteArrayResource(logoImage.getImageByte()); message.addInline(logoImage.getImageName(), imageLogo, logoImage.getImageType()); // Add the inline footer image, referenced from the HTML code as "cid:${imageResourceName}" final InputStreamSource imageFooter = new ByteArrayResource(footerImage.getImageByte()); message.addInline(footerImage.getImageName(), imageFooter, footerImage.getImageType()); // Add the attachment //final InputStreamSource attachmentSource = new ByteArrayResource(attachmentBytes); //message.addAttachment( // attachmentFileName, attachmentSource, attachmentContentType); // Send mail this.mailSender.send(mimeMessage); return recipientName + "OK"; }
From source file:cdr.forms.EmailNotificationHandler.java
private void sendReceipt(HashMap<String, Object> model, Form form, String recipient) { if (recipient == null || recipient.trim().length() == 0) return;//from ww w . ja v a 2s .c o m StringWriter htmlsw = new StringWriter(); StringWriter textsw = new StringWriter(); try { depositReceiptHtmlTemplate.process(model, htmlsw); depositReceiptTextTemplate.process(model, textsw); } catch (TemplateException e) { LOG.error("cannot process email template", e); return; } catch (IOException e) { LOG.error("cannot process email template", e); return; } try { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper message = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED); message.addTo(recipient); message.setSubject("Deposit Receipt for " + form.getTitle()); message.setFrom(this.getFromAddress()); message.setText(textsw.toString(), htmlsw.toString()); this.mailSender.send(mimeMessage); } catch (MessagingException e) { LOG.error("problem sending deposit message", e); return; } }