Use generic-email adapter

The Email Adapter (generic-email) adds an element of reporting into your workflows by providing basic functionality to send emails using an SMTP server. For the 1.0.0 adapter version, you can use the Send activity to send an email with a message defined inside the workflow definition.

Get generic-email adapter

Download the CWM 2.0 Software package. The cwm.v2.0.generic.email.v1.0.0.tar.gz file is included inside the package.

Install adapter

To install the adapter, follow the instructions on [how to install an adapter] in the Operator guide.

Create SMTP resource and secret

Before going into the details of defining your email message inside a workflow, you need to add a resource and a secret to CWM. You will later need to reference them inside your workflow.

Add secret

  1. In CWM, navigate to the Admin -> Secrets tab.
  2. Click Add Secret.
  3. In the New secret view, specify the following:
    • Secret ID: name your secret. You'll need to reference this secret ID later in the resource and inside the workflow. E.g. emailSecret.
    • Secret type: select basicAuth.
  4. After selecting the secret type, a set of additional fields is displayed under the Secret type details section. Fill in the fields with the following:
    • password: provide password to your sender email address.
    • username: provide the address you will send the email from in the format sender@address.com.
  5. Click Create Secret.

Add resource

  1. In CWM, navigate to the Admin -> Resources tab.
  2. Click Add Resource.
  3. In the New resource window, specify the following:

    • Resource name: name your resource. You'll need to provide the resource ID later inside the workflow as a reference. E.g. emailResource.
    • Resource type: select generic.email.resource.v1.0.0.
    • Secret ID: provide the ID of the secret you've just added.
    • Connection:
      • Host: provide the address of the SMTP server to be used.
      • Port: provide the SMTP port. The standard SMTP ports for encrypted email transmissions are either 587 or 25.
      • Scheme: this field is not required.
      • Timeout: this field is not required.
      • Allow Insecure: select true.
  4. Click Create resource.

Define the Send activity in workflow

Set activity reference

In CWM, the adapter Send activity is referred to as generic.email.smtp.Send. When defining a workflow, you need to specify it as the value of the operations parameter under functions:

  "functions": [
    {
      "name": "smtp.send",
      "operation": "generic.email.v1.0.0.smtp.Send"
    }
  ]
tip.gif

Tipblank.gifInside the name parameter, provide an activity name that you will later refer to in the refName parameter while defining the action.


Define email message in actions

Now you can define an action in which an email will be sent as part of a workflow state.

The available input parameters for the action are:

Field Type Label Description
from string Sender email address
to string repeated List of recipient email addresses
cc string repeated List of recipient cc email addresses
bcc string repeated List of recipient bcc email addresses
subject string Email title
text string Email body as text
html string Email body as html

Use the available fields as the input key/value pairs within the arguments that define the SendEmail example action as shown below:

  "states":[
    {
      "name":"EmailState",
      "type":"operation",
      "end": true,
      "actions": [
        {
          "name": "SendEmail",
          "functionRef": {
            "refName": "smtp.send",
            "arguments": {
              "input": {
                "to": ["recipient1@address.com", "recipient2@address.com"],
                "from": "sender@address.com",
                "text": "Hello, this is some placeholder email text.",
                "subject": "A test email from CWM"
              },
              "config": {
                "resourceId": "emailResource"
              }
            }
          }
        }
      ]
    }
  ]

If you want to trigger the email action based on a condition, you can use the [Switch state and define the dataConditions parameter] inside it. For details, check out the Serverless Workflow Specification documentation for the Switch state.