Warning!
This is a legacy document. The features described below are only usable within the classic generation environment. If you're working in the next-gen environment, you might be interested in learning how to use the send e-mail via SMTP function.
After you have followed this tutorial you will know how to use the Send mail action step to send emails to multiple accounts.
The Send mail step is used to send emails. The Send mail step uses templates for their content, in which you can include data from your application. In this example, a collection of records is sent to an employee.
This step works well in combination with a scheduled action, for more information about scheduled actions you can check out this article: How to 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 this case: Employee).
Click on the Save button when you are done with setting up the action.
Add a step
Click on the +
icon to add a new step. Out of the available kinds, choose Send mail.
This will change the form on your page to configure your step.
Enter a value in at least the following fields, while the rest is optional:
Template: Which template is used to generate the email's content? Create a new template or choose an existing one.
Subject: Set a subject for the email, which is the first thing the receiver of the email sees when receiving the email.
To email: Set the email address to which the email is being sent.
From email: Set the email address from which the email 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?
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: How to 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
In our email, it would be kind of nice to include a message or at least some data from our application. Template variables are the way to go.
Template variables
Template variables form a bridge from our action to the eventually generated email. 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 step.
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 and How to 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 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 email step 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:
Of course, this is an example that uses an Employee with a few activities. But the Send mail step can be used using any model or a different example!