How to use the send mail action

The Send mail event is used to… well, send emails! The Send mail event uses templates for their content, in which you can include data from your application.

In our example, we're sending a collection of records to an employee.This event works well in combination with a scheduled action, for more information about scheduled actions you can check out this article: HowTo create a scheduled action.

Create an action

Go to Actions by clicking on the Actions icon in the Builder Bar.Create a new action by clicking on the New button on the upper left side of the screen, and enter a fitting description and choose a model to execute the action on (in our case Employee). Click on the Save button when you are done with setting up the action.

Add an event

Click on the `+` sign to add a new event. Out of the available kinds, choose Send mail.
This will change the form on your page to configure your event. 

Enter a value in at least the following fields, while the rest is optional:

  • Template: Which template is used to generate the mail's content? Create a new template or choose an existing one.
  • Subject: Set a subject for the email, which is the first thing they'll see when receiving the mail.
  • To email: Set the email address to which the mail is being sent.
  • From email: Set the email address from which the mail is being sent.

Choose set values, or select variables to use dynamic values in the email. When all settings have been entered, click save, and it should look something like this:


A few things to look out for:

  • The From email setting needs to be entered with an accepted value. This means the domain from which the email is sent, needs to be verified on the Mandrill mail server used by the application. This can be ours, or a Mandrill server of your own. More information about this can be found here: How can I send emails from my own domain? ( error: unsigned )
  • The Track opens and Track clicks settings are used to register activity in the email after sending. Whenever the email is opened or clicked on, a webhook notification is sent. More information can be found here: HowTo create callback actions on mail triggers?
  • When using a variable in one of the settings, single or multiple values are accepted. This means when setting a collection variable in, for example, the To email setting, the email ends up being sent to multiple recipients.

Add data to the template

Besides sending the mail, we also want to include a message, or at least some data from our application. Template variables are the way to go. 

Template variables

Template variable form a bridge from our action to the eventually generated mail. If we want to include data from the action, we must 'contain' the data in a variable, and parse it in our template from the email event.
First of all, we need HTML and Liquid to mark up our mail's content. How to include HTML and Liquid in templates can be found here: Template Language Reference andHowTo use the Liquid Template Language to display dynamic content on your templates.

For example, we want to include the employee's activities from last week.We'll have to add at least 2 template variables: the employee record and a collection of last week's activities. The template variable names do not have to match, nor do they have to differ from the names of existing variables, as long as they match the names used in the template's content. Take a look at this example:

By including `employee` in our Liquid, we show the employee's data, and with `activities`, we can access the activities' collection's data.After using tags and `output` in our Liquid, our template looks like this:

<!DOCTYPE html>
<html>
<head>
<style>
table {
  border-collapse: collapse;
  width: 80%;
}
td, th {
  border: 1px solid;
  text-align: center;
}
</style>
</head>
<body>
<p>Hi {{employee.name}},</p>
<p>This is an overview of your activities from last week.</p>
<table>
  <tr>
    <th>Activity</th>
    <th>Start time</th> 
    <th>End time</th>
  </tr>
{% for activity in activities%}
  <tr>
    <td>{{activity.desription}}</td>
    <td>{{activity.start_time}}</td> 
    <td>{{activity.end_time}}</td>
  </tr>
{% endfor %}
</table>
</body>
</html>
Testing the action

With the action and event in place, it's time to try out the action. Click on the green Run test button to initiate the action. 


You'll be prompted to choose a record. This record is the data on which the action is executed. We'll go with Marcel this time. Press Execute and shortly after, you'll receive a Success message.


Go to the mailbox of the chosen employee and look for the newly sent email. If all went right, the outcome should be something like: