Java Code Examples for org.springframework.mail.javamail.MimeMessageHelper#setSentDate()

The following examples show how to use org.springframework.mail.javamail.MimeMessageHelper#setSentDate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmailNotificationServiceImpl.java    From podcastpedia-web with MIT License 6 votes vote down vote up
public void sendContactNotification(final ContactForm contactForm) {
      MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @SuppressWarnings({ "rawtypes", "unchecked" })
		public void prepare(MimeMessage mimeMessage) throws Exception {
             MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
             message.setTo(configService.getValue("EMAIL_TO_CONTACT_MESSAGE"));
             message.setBcc("[email protected]");
             message.setFrom(new InternetAddress(contactForm.getEmail()));
             message.setSubject("New contact message " + contactForm.getTopic());
             message.setReplyTo(contactForm.getEmail());
             message.setSentDate(new Date());
             Map model = new HashMap();	             
             model.put("newMessage", contactForm);
             
             String text = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, "velocity/newContactMessageToAdmin.vm", "UTF-8", model);
             message.setText(text, true);
          }
       };
       this.mailSender.send(preparator);	  
}
 
Example 2
Source File: EmailNotificationServiceImpl.java    From podcastpedia-web with MIT License 6 votes vote down vote up
public void sendSuggestPodcastNotification(final SuggestedPodcast suggestedPodcast) {
      MimeMessagePreparator preparator = new MimeMessagePreparator() {
	        @SuppressWarnings({ "rawtypes", "unchecked" })
			public void prepare(MimeMessage mimeMessage) throws Exception {
	             MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
	             message.setTo(configService.getValue("EMAIL_TO_SUGGEST_PODCAST"));
	             message.setBcc("[email protected]");
	             message.setFrom(new InternetAddress(suggestedPodcast.getEmail()) );
	             message.setSubject("New suggested podcast");
	             message.setSentDate(new Date());
	             Map model = new HashMap();	             
	             model.put("newPodcast", suggestedPodcast);		             
	             String text = VelocityEngineUtils.mergeTemplateIntoString(
	                velocityEngine, "velocity/suggestPodcastNotificationMessage.vm", "UTF-8", model);
	             message.setText(text, true);
	          }
	       };
	       mailSender.send(preparator);			
}
 
Example 3
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 4
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 5
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 6
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 7
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 8
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 9
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 10
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 11
Source File: GmailService.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void sendMessage(String to, String subject, String text)  {
	MimeMessage message = mailSender.createMimeMessage();
    try {
    	MimeMessageHelper helper = new MimeMessageHelper(message, false);
    	message.setContent(text, "text/html; charset=UTF-8");
     helper.setTo(to);
     helper.setSubject(subject);
     helper.setSentDate(new Date());
     mailSender.send(message);
 } catch (MessagingException e) {
     throw new RuntimeException(e);
 }
}
 
Example 12
Source File: MailSenderImpl.java    From cerebro with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void send(final String title, final String text, final List<String> recipients) {
    MimeMessagePreparator preparator = mimeMessage -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
        message.setTo(toInternetAddresses(recipients));
        message.setFrom(properties.getProperty("sender"));
        message.setSubject(title);
        message.setSentDate(new Date());

        message.setText(text, true);
    };
    LOGGER.debug("send mail with title: {}", title);
    mailSender.send(preparator);
}
 
Example 13
Source File: EmailUtil.java    From SpringBoot-Home with Apache License 2.0 4 votes vote down vote up
/**
 * 构建复杂邮件信息类
 * @param mail
 * @throws MessagingException
 */
public void sendMail(MailDomain mail) throws MessagingException {

    //true表示支持复杂类型
    MimeMessageHelper messageHelper = new MimeMessageHelper(mailSender.createMimeMessage(), true);
    //邮件发信人从配置项读取
    mail.setSender(sender);
    //邮件发信人
    messageHelper.setFrom(mail.getSender());
    //邮件收信人
    messageHelper.setTo(mail.getReceiver().split(","));
    //邮件主题
    messageHelper.setSubject(mail.getSubject());
    //邮件内容
    if (mail.getIsTemplate()) {
        // templateEngine 替换掉动态参数,生产出最后的html
        String emailContent = templateEngine.process(mail.getEmailTemplateName(), mail.getEmailTemplateContext());
        messageHelper.setText(emailContent, true);
    }else {
        messageHelper.setText(mail.getText());
    }
    //抄送
    if (!StringUtils.isEmpty(mail.getCc())) {
        messageHelper.setCc(mail.getCc().split(","));
    }
    //密送
    if (!StringUtils.isEmpty(mail.getBcc())) {
        messageHelper.setCc(mail.getBcc().split(","));
    }
    //添加邮件附件
    if (mail.getFilePath() != null) {
        File file = new File(mail.getFilePath());
        messageHelper.addAttachment(file.getName(), file);
    }
    //发送时间
    if (StringUtils.isEmpty(mail.getSentDate())) {
        messageHelper.setSentDate(mail.getSentDate());
    }
    //正式发送邮件
    mailSender.send(messageHelper.getMimeMessage());
}
 
Example 14
Source File: MailComposerImpl.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
void composeMessage(final MimeMessage message,
                    final String shopCode,
                    final String locale,
                    final List<String> mailTemplateChain,
                    final String templateName,
                    final String from,
                    final String toEmail,
                    final String ccEmail,
                    final String bccEmail,
                    final Map<String, Object> model)
        throws MessagingException, IOException, ClassNotFoundException {


    final MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");

    helper.setTo(toEmail);

    helper.setSentDate(new Date());

    if (ccEmail != null) {
        helper.setCc(ccEmail);
    }

    if (bccEmail != null) {
        helper.setBcc(bccEmail);
    }


    final String textContent = processTemplate(mailTemplateChain, shopCode, locale, templateName, ".txt", model);
    final String htmlContent = processTemplate(mailTemplateChain, shopCode, locale, templateName, ".html", model);
    final String propString = processTemplate(mailTemplateChain, shopCode, locale, templateName, ".properties", model);
    final Properties prop = new Properties();
    if (propString != null) {
        prop.load(new StringReader(propString));
    }
    helper.setSubject(prop.getProperty("subject"));

    if (from == null) {
        helper.setFrom(prop.getProperty("from"));
    } else {
        helper.setFrom(from);
    }

    final Map<String, byte[]> attachments = collectAttachments(model);

    composeMessage(helper, textContent, htmlContent, attachments, mailTemplateChain, shopCode, locale, templateName);

}
 
Example 15
Source File: MailComposerImpl.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void convertMessage(final Mail mail, final MimeMessage mimeMessage)
        throws MessagingException, IOException, ClassNotFoundException {

    final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");

    helper.setTo(mail.getRecipients());

    helper.setSentDate(new Date());

    if (mail.getCc() != null) {
        helper.setCc(mail.getCc());
    }

    if (mail.getBcc() != null) {
        helper.setBcc(mail.getBcc());
    }

    final String textTemplate = mail.getTextVersion();
    final String htmlTemplate = mail.getHtmlVersion();

    helper.setSubject(mail.getSubject());
    helper.setFrom(mail.getFrom());

    if (textTemplate == null || htmlTemplate == null) {
        if (textTemplate != null) {
            helper.setText(textTemplate, false);
        }

        if (htmlTemplate != null) {
            helper.setText(htmlTemplate, true);
            inlineResources(helper, mail);
        }

    } else {
        helper.setText(textTemplate, htmlTemplate);
        inlineResources(helper, mail);
    }

}