Example #1
0
  protected void send(DocumentModel doc)
      throws TemplateException, RenderingException, OperationException, MessagingException,
          IOException {
    // TODO should sent one by one to each recipient? and have the template
    // rendered for each recipient? Use: "mailto" var name?
    try {
      Map<String, Object> map = Scripting.initBindings(ctx);
      // do not use document wrapper which is working only in mvel.
      map.put("Document", doc);
      map.put("docUrl", MailTemplateHelper.getDocumentUrl(doc, viewId));
      map.put("subject", subject);
      map.put("to", to);
      map.put("toResolved", MailBox.fetchPersonsFromList(to, isStrict));
      map.put("from", from);
      map.put("fromResolved", MailBox.fetchPersonsFromString(from, isStrict));
      map.put("from", cc);
      map.put("fromResolved", MailBox.fetchPersonsFromList(cc, isStrict));
      map.put("from", bcc);
      map.put("fromResolved", MailBox.fetchPersonsFromList(bcc, isStrict));
      map.put("from", replyto);
      map.put("fromResolved", MailBox.fetchPersonsFromList(replyto, isStrict));
      map.put("viewId", viewId);
      map.put("baseUrl", NotificationServiceHelper.getNotificationService().getServerUrlPrefix());
      map.put("Runtime", Framework.getRuntime());
      Mailer.Message msg = createMessage(doc, getContent(), map);
      msg.setSubject(subject, "UTF-8");

      addMailBoxInfo(msg);

      msg.send();
    } catch (ClientException
        | TemplateException
        | RenderingException
        | OperationException
        | MessagingException
        | IOException e) {
      if (rollbackOnError) {
        throw e;
      } else {
        log.warn(
            String.format(
                "An error occured while trying to execute the %s operation, see complete stack trace below. Continuing chain since 'rollbackOnError' was set to false.",
                ID),
            e);
      }
    }
  }
Example #2
0
  /** @since 5.9.1 */
  private void addMailBoxInfo(Mailer.Message msg) throws MessagingException {
    List<MailBox> persons = MailBox.fetchPersonsFromString(from, isStrict);
    addMailBoxInfoInMessageHeader(msg, AS.FROM, persons);

    persons = MailBox.fetchPersonsFromList(to, isStrict);
    addMailBoxInfoInMessageHeader(msg, AS.TO, persons);

    persons = MailBox.fetchPersonsFromList(cc, isStrict);
    addMailBoxInfoInMessageHeader(msg, AS.CC, persons);

    persons = MailBox.fetchPersonsFromList(bcc, isStrict);
    addMailBoxInfoInMessageHeader(msg, AS.BCC, persons);

    if (replyto != null && !replyto.isEmpty()) {
      msg.setReplyTo(null);
      persons = MailBox.fetchPersonsFromList(replyto, isStrict);
      addMailBoxInfoInMessageHeader(msg, AS.REPLYTO, persons);
    }
  }