Example usage for org.springframework.mail.javamail MimeMessageHelper setSentDate

List of usage examples for org.springframework.mail.javamail MimeMessageHelper setSentDate

Introduction

In this page you can find the example usage for org.springframework.mail.javamail MimeMessageHelper setSentDate.

Prototype

public void setSentDate(Date sentDate) throws MessagingException 

Source Link

Document

Set the sent-date of the message.

Usage

From source file:org.yes.cart.service.mail.impl.MailComposerImpl.java

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);/*from  w ww  .  j  a  v a 2s .  com*/

    helper.setSentDate(new Date());

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

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

    final String textTemplate = getTemplate(mailTemplateChain, shopCode, locale, templateName, ".txt");
    final String htmlTemplate = getTemplate(mailTemplateChain, shopCode, locale, templateName, ".html");
    final String propString = getTemplate(mailTemplateChain, shopCode, locale, templateName, ".properties");
    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);
    }

    composeMessage(helper, textTemplate, htmlTemplate, mailTemplateChain, shopCode, locale, templateName,
            model);

}

From source file:org.yes.cart.service.mail.impl.MailComposerImpl.java

/** {@inheritDoc} */
@Override/*from  w  w  w .j  av  a  2  s  . c o m*/
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);
    }

}