Ejemplo n.º 1
0
 @Override
 public void sendTextMailWithClasspathTemplate(
     final MailMetaData mailMetaData,
     final String templateLocation,
     final MailContentModel model) {
   LOGGER.info("Entering method sendTextMailWithClasspathTemplate..");
   model.add("mailMeta", mailMetaData);
   try {
     final String result =
         FreeMarkerTemplateUtils.processTemplateIntoString(
             freemarkerMailConfiguration.getTemplate(templateLocation), model.getModel());
     sendTextMail(mailMetaData, result);
   } catch (Exception e) {
     throw new SendMailException(
         new StringBuilder()
             .append("Error sending mail: ")
             .append(mailMetaData.toString())
             .toString(),
         e);
   }
   LOGGER.info("Exiting method sendTextMailWithClasspathTemplate..");
 }
Ejemplo n.º 2
0
 @Override
 public void sendTextMail(final MailMetaData mailMetaData, final String text) {
   if (suppressMail) {
     return;
   }
   final SimpleMailMessage mailMessage = new SimpleMailMessage();
   mailMessage.setFrom(
       new StringBuilder()
           .append(mailMetaData.getFromName())
           .append(" <")
           .append(mailMetaData.getFromAddress())
           .append(">")
           .toString());
   mailMessage.setSubject(mailMetaData.getSubject());
   mailMessage.setReplyTo(mailMetaData.getReplyTo());
   if (mailMetaData.getCcAddresses() != null && mailMetaData.getCcAddresses().size() > 0) {
     mailMessage.setCc(
         (String[])
             mailMetaData
                 .getCcAddresses()
                 .toArray(new String[mailMetaData.getCcAddresses().size()]));
   }
   if (mailMetaData.getBccAddresses() != null && mailMetaData.getBccAddresses().size() > 0) {
     mailMessage.setBcc(
         (String[])
             mailMetaData
                 .getBccAddresses()
                 .toArray(new String[mailMetaData.getBccAddresses().size()]));
   }
   if (mailMetaData.getToAddresses() != null && mailMetaData.getToAddresses().size() > 0) {
     mailMessage.setTo(
         (String[])
             mailMetaData
                 .getToAddresses()
                 .toArray(new String[mailMetaData.getToAddresses().size()]));
   }
   mailMessage.setText(text);
   try {
     mailSender.send(mailMessage);
   } catch (MailException e) {
     throw new SendMailException(
         new StringBuilder()
             .append("Error sending mail: ")
             .append(mailMetaData.toString())
             .toString(),
         e);
   }
 }