Emailling
SINCE VERSION 1.0
How to send Emails in PIPEFORCE?
In PIPEFORCE you can send email messages out-of-the-box using the mail.send command.
Here is an example pipeline to use this command:
pipeline:
- mail.send:
to: "recipient@domain.tld"
subject: "This is the subject"
message: |
Hello recipient,
this is an email sent from a pipeline.
Greetings
Email Templates
There are different possibilities in PIPEFORCE to set the email data dynamically.
Using PEL
As usual, you can use the Pipeline Expression Language (PEL) in order to define placeholders in the command parameters. For example:
vars:
name: "Sam"
email: "recipient@domain.tld"
pipeline:
- mail.send:
to: ${vars.email}
subject: "This is for ${vars.name}"
message: |
Hello ${vars.name},
this is an email sent from a pipeline.
Greetings
Using a Transformer Command
You can use a transformer command like transform.ftl in order to render the message. For example:
vars:
name: "Sam"
email: "recipient@domain.tld"
pipeline:
- transform.ftl:
template: |
Hello ${vars.name},
this is an email sent from a pipeline.
Greetings
- mail.send:
to: ${vars.email}
subject: "This is for ${vars.name}"
In this example, the message is rendered and then stored in the body using transform.ftl
. The command mail.send
then picks up the rendered message from the body and uses it as email message.
And here is an example to load the template from the property store from location global/app/myapp/template/email
:
Using a Custom URI
Instead of defining a separate transformer command in the pipeline, you can use a Custom URI which points inline to a template. For example:
In this case, the mail.send
command loads the template as property from location global/app/myapp/template/email
, renders it and uses the result as email message. The variables var
, header
and body
will be provided as default model to the template.
You can replace these default template variables by your custom model
:
Email Attachments
In case you would like to add attachments, you can use the parameter attachments
to do so.
From Body
One approach is to load the attachments into a scope, like vars or the body first and then refer to them using a PEL inside the parameter attachments
. For example:
In this example the file is first loaded (implicitly) to body using the command drive.read
and then linked to the attachments
parameter. You can place any content object as attachment.
Using this approach it is also possible to create the attachments dynamically on-the-fly in the pipeline (for example by using a template engine) and then add them finally to the email.
From Custom URI
Another approach to add attachments to an email is by using a Custom URI which points to the location of the attachments. For example:
You can add multiple attachments by separating them by comma.
HTML Emails
Emails are sent by default using a base HTML skeleton. Any message is placed as text inside this HTML skeleton. HTML tags will be escaped by default.
In case you would like to format the text using HTML tags, you need to place the whole message inside a single HTML tag like <p>
and </p>
for example.
Here is an example to place a HTML link and HTML bullet points in your email message:
This will produce an email message output similar to this:
Bulk Emails
Sending multiple emails to multiple recipients with dynamic content can be done using the mail.send
command in combination with the foreach
command.
Depending on your license and/or environment, the number of allowed emails to be send per minute is restricted. Please refer to your support in order to get information about this limit. In case you need to send a higher amount of emails, consider to use one of the email services and integrate their API using the http.*
commands.
Testing Emails (dryRun)
In case you would like to test whether an email would be send correctly and contains all required information but without sending it to a real, external SMTP server / recipient, you can add a marker to the email subject or the email address. In case PIPEFORCE finds at least one such marker, it will store the email into the cache instead of real sending it. This way you can later pick-up this email from cache (instead of email inbox) and check it in your (automated) tests.
In case both, subject and email markers are set, the name of the subject marker will have precedence.
DryRun marker in subject
In case the marker [pipeforce.dryrun:someName]
is set in the subject of an email, the whole email will be stored to cache under key pipeforce.dryrun:someName
. Make sure to replace someName
by your custom name without any whitespaces or special characters. Example:
As you can see, in this example the dryrun marker is [pipeforce.dryrun:testrun1]
so this email wont be send to external. Instead, it will be stored to the internal cache using the key pipeforce.dryrun:testrun1
. You can load the email from cache using the cache.get
command. For example:
DryRun marker in email address
Sometimes it is not possible to change the subject to place the dryrun marker there (for example in case of system messages). In this case you can add email address which is ending in @pipeforce.dryrun
(for example testrun1@pipeforce.dryrun
) to one of the TO, CC or BCC addresses. As soon as at least one of such an dryrun email address marker exists, the whole email wont be delivered to external, even if it contains additional “real” email addresses. Instead, it will be stored into the local cache using the email address as suffix such as this example key shows: pipeforce.dryrun:testrun1
. Example:
As you can see, in this example the dryrun marker email address is testrun1@pipeforce.dryrun
so this email wont be send to external. Instead, it will be stored to the internal cache using the key pipeforce.dryrun:testrun1
. You can load the email from cache using the cache.get
command. For example: