Sending Email Using Scripts or Hooks

If you’re creating a pipeline, the preferred method of sending an email is to use the SendMail pipelet. However, to create an OC API hook to send email or send email from inside a script, you can use dw.net.mail class to construct an email and send it. You can also use dw.net.mail with the new dw.util.Template class to construct an email using an ISML template.

  • With dw.net.Mail you must set the subject, mail body, and the to, cc, or bcc. If you don’t, the invocation of mail.send() fails with an IllegalArgumentException.
  • Any tags provided in a template for to, from, subject, or other fields are ignored and not used. Only the values provided by the dw.net.Mail.set* arguments are used to generate an email.
  • Although a variable called pdict is accessible from within the ISML template, it isn't the Pipeline Dictionary. Pipeline Dictionary default data, such as Session, isn’t accessible.
  • The Mail.send() returns the OK status if the email is successfully queued to the internal mailing queue, or ERROR if the email couldn’t be queued. The email itself is placed on the mail queue asynchronously, meaning that it isn’t sent if there’s a problem with the mail server.

The following script uses the dw.net.Mail setter methods to create an email using only simple strings.

The following script uses the dw.net.Mail setter methods to create an email with an HTML body and header information.

The following script uses the dw.net.Mail setter methods to create an email and send it to the internal mail queue.

Because mail can be sent outside the scope of a Pipeline Dictionary, we can't rely on using Pipeline Dictionary access. Although the pdict variable is still available, it isn't the Pipeline Dictionary. All data within a Pipeline Dictionary is only available if it's within the parameter map at rendering time.

A simple template with some customized content for a specific user.

Access parameters created in the parameter map in the script through <isprint value="${param.parameter}">, as this name reflects the type of object one is working with.

This script:

  1. Creates a parameter map, which holds all parameters required to render the template.
  2. Specifies and renders a template with the given parameter map
  3. Creates a mail object and a mail body, using the MIME encoded text generated by rendering the template in the previous step.