List of usage examples for javax.mail Message setSentDate
public abstract void setSentDate(Date date) throws MessagingException;
From source file:rapture.mail.Mailer.java
public static void email(CallingContext context, String templateName, Map<String, ? extends Object> templateValues) { final SMTPConfig config = getSMTPConfig(); Session session = getSession(config); EmailTemplate template = getEmailTemplate(context, templateName); try {/*ww w . ja v a 2 s .c om*/ // Instantiate a new MimeMessage and fill it with the required information. Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(config.getFrom())); String to = renderTemplate(template.getEmailTo(), templateValues); if (StringUtils.isBlank(to)) { throw RaptureExceptionFactory.create("No emailTo field"); } InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(renderTemplate(template.getSubject(), templateValues)); msg.setSentDate(new Date()); msg.setContent(renderTemplate(template.getMsgBody(), templateValues), "text/html; charset=utf-8"); // Hand the message to the default transport service for delivery. Transport.send(msg); } catch (MessagingException e) { log.error("Failed to send email", e); } }
From source file:rapture.mail.Mailer.java
public static void email(String[] recipients, String subject, String message) throws MessagingException { final SMTPConfig config = getSMTPConfig(); Session session = getSession(config); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(config.getFrom())); InternetAddress[] address = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) address[i] = new InternetAddress(recipients[i]); msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject);/* ww w . j ava 2s. co m*/ msg.setContent(message, MediaType.PLAIN_TEXT_UTF_8.toString()); msg.setSentDate(new Date()); Transport.send(msg); }