List of usage examples for org.springframework.mail SimpleMailMessage getSentDate
@Nullable
public Date getSentDate()
From source file:ar.com.zauber.commons.spring.mail.AbstractMailSender.java
/** Creates a text representation for simpleMessages */ public static String toString(final SimpleMailMessage[] simpleMessages) { final StringBuilder sb = new StringBuilder(); sb.append("This window show that the system tried to send an email.\n").append('\n') .append("The email wasnt sent. To do change the AppContext.\n"); for (final SimpleMailMessage message : simpleMessages) { sb.append(" --------------8<--------------\n"); if (message.getFrom() != null) { sb.append("From: ").append(message.getFrom()); }// www.j a v a2 s .c om if (message.getTo() != null) { sb.append("\nTo: ").append(Arrays.asList(message.getTo())); } if (message.getCc() != null) { sb.append("\nCc: ").append(Arrays.asList(message.getCc())); } if (message.getBcc() != null) { sb.append("\nBcc: ").append(Arrays.asList(message.getBcc())); } if (message.getReplyTo() != null) { sb.append("\nReply-To: ").append(message.getReplyTo()); } if (message.getSentDate() != null) { sb.append("\nDate: ").append(message.getSentDate()); } if (message.getSubject() != null) { sb.append("\nSubject: ").append(message.getSubject()); } sb.append("\n\n").append(message.getText()); } return sb.toString(); }
From source file:ar.com.zauber.commons.spring.mail.RepositoryMailMessage.java
/** constructor de copia */ public RepositoryMailMessage(final SimpleMailMessage m) { setBcc(m.getBcc());//from w ww . ja v a 2 s . c o m setCc(m.getCc()); setFrom(m.getFrom()); setReplyTo(m.getReplyTo()); setSentDate(m.getSentDate()); setSubject(m.getSubject()); setText(m.getText()); setTo(m.getTo()); }
From source file:net.triptech.metahive.service.EmailSenderService.java
/** * Send an email message using the configured Spring sender. On success * record the sent message in the datastore for reporting purposes * * @param email the email/*from w ww.jav a 2 s . c om*/ * @param attachments the attachments * @throws ServiceException the service exception */ public final void send(final SimpleMailMessage email, TreeMap<String, Object> attachments) throws ServiceException { // Check to see whether the required fields are set (to, from, message) if (email.getTo() == null) { throw new ServiceException("Error sending email: Recipient " + "address required"); } if (StringUtils.isBlank(email.getFrom())) { throw new ServiceException("Error sending email: Email requires " + "a from address"); } if (StringUtils.isBlank(email.getText())) { throw new ServiceException("Error sending email: No email " + "message specified"); } if (mailSender == null) { throw new ServiceException("The JavaMail sender has not " + "been configured"); } // Prepare the email message MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = null; boolean htmlMessage = false; if (StringUtils.containsIgnoreCase(email.getText(), "<html")) { htmlMessage = true; try { helper = new MimeMessageHelper(message, true, "UTF-8"); } catch (MessagingException me) { throw new ServiceException("Error preparing email for sending: " + me.getMessage()); } } else { helper = new MimeMessageHelper(message); } try { helper.setTo(email.getTo()); helper.setFrom(email.getFrom()); helper.setSubject(email.getSubject()); if (email.getCc() != null) { helper.setCc(email.getCc()); } if (email.getBcc() != null) { helper.setBcc(email.getBcc()); } if (htmlMessage) { String plainText = email.getText(); try { ConvertHtmlToText htmlToText = new ConvertHtmlToText(); plainText = htmlToText.convert(email.getText()); } catch (Exception e) { logger.error("Error converting HTML to plain text: " + e.getMessage()); } helper.setText(plainText, email.getText()); } else { helper.setText(email.getText()); } if (email.getSentDate() != null) { helper.setSentDate(email.getSentDate()); } else { helper.setSentDate(Calendar.getInstance().getTime()); } } catch (MessagingException me) { throw new ServiceException("Error preparing email for sending: " + me.getMessage()); } // Append any attachments (if an HTML email) if (htmlMessage && attachments != null) { for (String id : attachments.keySet()) { Object reference = attachments.get(id); if (reference instanceof File) { try { FileSystemResource res = new FileSystemResource((File) reference); helper.addInline(id, res); } catch (MessagingException me) { logger.error("Error appending File attachment: " + me.getMessage()); } } if (reference instanceof URL) { try { UrlResource res = new UrlResource((URL) reference); helper.addInline(id, res); } catch (MessagingException me) { logger.error("Error appending URL attachment: " + me.getMessage()); } } } } // Send the email message try { mailSender.send(message); } catch (MailException me) { logger.error("Error sending email: " + me.getMessage()); throw new ServiceException("Error sending email: " + me.getMessage()); } }