Table of Contents

Action: Create an email from template

This article explores the "Create an email from template" action from our Power Automate Connector.

Intro

This action generates HTML for an email body based on a chosen template from the "Flow template" section in your DeskDirector admin console. It does not have any send functionality, so needs to be used in tandem with a send action from another connector e.g Outlook.

The advantages of using this action are:

  • Styling: you can easily craft good looking, responsive emails instead of sending plain HTML. If you've used Outlook's "Send an email" action in Power Automate, you are likely sending emails without any styling. It is possible to add inline styling but this is hard to do within the small text box.
  • Dynamic Content: you can leverage Liquid template language to process input tokens or customise email content before sending.

See these related articles if you are unfamiliar with our email template engine.

Usage

  1. In admin console, have an existing custom email template in the "Flow template" section. If your template is not in this section, it will not appear in the Power Automate action.
  2. In Power Automate, add the "Create an email from template" action and select your template from the dropdown.
  3. If your template has any custom tokens, they will appear as inputs so you can enter values for them.
  4. Use a send action from another connector e.g Office 365 Outlook - Send an email. For the email body, select the output of "Create an email from template". If you are using the Outlook action, switch the body input to Code View (</> button).
  5. Your flow should look like the following. ContactName is a custom token specified in the template.

Implementation Example

In this example, we will be extending the "Unassigned open tickets digest" flow to use a custom email template. The flow template can be downloaded from our Template Gallery.

Create the email template

Firstly, create the email template we have prepared. There are two ways to do this:

  1. Import via your DeskDirector instance's Swagger UI
    1. Navigate to https://{subdomain}.deskdirector.com/swagger
    2. Find this API under v3, Email Templates: POST /api/v3/email/types/{type}/templates. You won't need an API key if you are already logged in to your instance as an admin.
    3. Enter the following:
      1. type: dynamic
      2. req: paste the contents of this file: UnassignedTicketsDigestEmail.json
      3. Parameter content type: application/json
    4. Press Try it out! button. This will create the email template in your instance.
  2. Or, manually create the template
    1. Create a new custom template under the Flow template section. Call it "Unassigned Tickets Digest Email Template"
    2. In the Code tab, replace the sample code with the contents of this file: UnassignedTicketsDigestEmailMjml.txt
    3. There will be some errors because some tokens have not been created yet. In the Tokens tab, create three custom tokens:
      1. totalCount: number. Sample: 50
      2. resultsCount: number. Sample: 20
      3. htmlTableString: string. Sample: <table><tr><th>col1</th><th>col2</th></tr></table>
    4. The template should now be error free, save

The template is now ready to use in Power Automate.

Use in Power Automate Flow
  1. Add the Create an email from template action between Create HTML table and Send an email (V2) actions.
  2. Configure the Create an email from template action:
    1. Template: select the template we just created: Unassigned Tickets Digest Email Template
    2. totalCount: total from Find tickets
    3. resultsCount: resultsCount from Find tickets
    4. htmlTableString: Output from Create HTML table
  3. Configure the Send an email (V2) action:
    1. Body
      1. Delete all existing content
      2. Switch to Code View, </> button
      3. Content from Create an email from template
  4. The final result will look like the following image. Run the flow to see the email template in action.

How did we do?

DeskDirector Connector Triggers

Power Automate Connector - Setting up your first flow

Contact