Esempio n. 1
0
  /**
   * Send a simple message based on a Velocity template.
   *
   * @param msg
   * @param templateName
   * @param model
   */
  public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
      result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, model);
    } catch (VelocityException e) {
      e.printStackTrace();
    }

    msg.setText(result);
    send(msg);
  }
Esempio n. 2
0
  /**
   * Send a simple message based on a Velocity template.
   *
   * @param msg
   * @param templateName
   * @param model
   */
  @SuppressWarnings("unchecked")
  public void sendMessage(PlanetsMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
      result = PlanetsMailer.mergeTemplateIntoString(velocityEngine, templateName, model);
    } catch (VelocityException e) {
      e.printStackTrace();
    }

    msg.setBody(result);
    send(msg);
  }
Esempio n. 3
0
  /**
   * Send a simple message based on a Velocity template.
   *
   * @param msg the message to populate
   * @param templateName the Velocity template to use (relative to classpath)
   * @param model a map containing key/value pairs
   */
  @SuppressWarnings("unchecked")
  public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
      result =
          VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, "UTF-8", model);
    } catch (VelocityException e) {
      e.printStackTrace();
      log.error(e.getMessage());
    }

    msg.setText(result);
    send(msg);
  }
Esempio n. 4
0
  public SimpleMailMessage mergeSimpleMessage(String to, Map<String, Object> model) {
    // render text of mail from velocity template with the data
    String text = null;
    try {
      text = renderText(model);
    } catch (VelocityException e) {
      log.error(e);
      e.printStackTrace();
    }

    // mail message setting
    SimpleMailMessage message = new SimpleMailMessage();
    message.setSubject(getSubject());
    message.setFrom(getFrom());
    message.setTo(to);
    message.setText(text);
    return message;
  }