Send Rich Email with the new SendHTMLEmail Action

Video introduction

Installation (See bottom of post)

Source code

Flow provides a built-in Send Email action but it’s something of an underachiever. However, using the power of Apex and Flow Actions, its possible to build a powerful SendHTMLEmail action that can be easily installed and used from within Flow Builder. MVP Jeremiah Dohn pioneered this space several years back with his well received HTML Email Flow action. The version here is similar and adds a couple of additional capabilities.

This improved email experience provides:

Rich, HTML email bodies that can use all of the capabilities of Flow’s Text Templates, including Bold, Italics, Underline, Bullets and Numbers, Left/Center/Right justification, URLs, images, fonts, and text size:

This action also allows you to use Email Templates (both Classic and Lightning), so long as you provide it with a recordId to a Contact, Lead, or User that can be used to fill in the merge fields of the template:

To make it easy to pass email addresses into the action, it supports any combination of the following, for To, CC, and BCC:

  • A single email address
  • A string collection of email addresses
  • A collection of Contacts
  • A collection of Users
  • A collection of Leads

Other supported features include:

  • Support for Organization-Wide Email Addresses
  • Support for Attachments
  • Ability to toggle on/off the use of the Salesforce per-user email signature
  • Ability to provide either a plain text body, an html body, or both
  • Ability to set the ReplyTo email address and the Sender Display Name


This sample flow ships with the action and can be used to test and demonstrate the action:

Here’s how I have my inputs configured in the above sample Flow for an HTML body from a Text Template:

Here’s how it would be configured for use with an Email Template. Note the plainTextBody, HTMLbody, and Subject are all nulled out (when “Don’t Include” is selected, null values are used):

You can use any of these five combinations:

  • An HTML Body
  • A plain text body
  • Both an HTML Body or a plain text body
  • A Classic Email Template
  • A Lightning Email Template

However, you’ll get errors if you try to mix your own bodies and subjects with Email Templates.

Using Templates

If you want to use an Email Template, you must pass in the Id (not the name) of the template. In the above flow example, I use a Get Record to query for an email template by name, and then pass in the ID to the SendHTMLEmail flow action. Importantly, you need to also pass in the recordId of a Contact, Lead, or User that will serve as the context record for the template and populate the template’s merge fields. Do this with the templateTargetObjectID parameter

Setting the Sender/ReplyTo Address

You can either 1) use an OrganizationWideEmailAddress or 2) specify your own Reply-To Email Address and Sender Display Name. If you provide an OrganizationWideEmailAddress, that will take precedence and any Reply-To Email Address and/or Sender Display Name you’ve also provided will be ignored.

To use an OrganizationWideEmailAddress , pass the Id of one that you have defined into the action via the “Use This Organization-Wide Email Address Id”. (If you want to get the benefit of Verified sending, you can’t just paste the email address into the Reply-To Email Address field. You have to use the Use This Organization-Wide Email Address Id field.). to find the ID:

  1. In Lightning Setup, go to Organization-Wide Addresses and click Edit on the address you want to use:

2. Examine the URL of this web page. It should look something like this:

3. The Id of the Organization-Wide Email Address is the character between the 2 “%2F” strings. So in the example above, you would extract “0D2560000008PGP” and insert it as an input:


You can pass in a collection of Attachments. In many cases, though, you’ll be working with Content Document Links that you’ve retrieved with a Get Records. This package also includes therefore an action called ConvertFilesToAttachments that takes a collection of Content Document Links and returns a collection of Attachments. For more information on the relationship between these various document-related types, see this.


This action makes use of the standard Salesforce email infrastructure, the same service that you use when you send a single email directly from a lightning experience page or a classic case feed. As such, any emails you send will be included in your usage, so be aware of the limits and guidelines. (Developer note: this action makes use of the Apex Messaging service API’s.)

This action does not use or involve Email Alerts, which are used in Workflow Rules and exist in Flow as separate actions you can drag into your flow. Be mindful of this so you don’t accidentally confuse the Email Alerts, the Email Templates, and the Flow Text Templates.

Currently unsupported features include:

  • Support for the MassEmailMessage API, enabling higher volumes
  • Character Set setting

If you’re interested in extending this class, please do so!


  • Install – 1.1 Unmanaged (adds Attachments and Organization-wide Email Addresses

Old versions

1.0 Unmanaged

1.0 – Managed (requires Winter ’20)

7 replies
  1. Kou Xiong
    Kou Xiong says:


    Tried installing it and got this error:

    “The AppExchange Application or component you have selected is not yet available on your instance of Please check back in a few days to retry the installation. Press the back button of your browser now and bookmark the AppExchange Directory page so that you can find it later.”

    On NA57 instance.

  2. Megan Moody
    Megan Moody says:

    I was able to get this work – awesome! – but the sender comes through as unverified. I’m populating the replyEmailAddress variable with one of our org-wide email addresses. Is it because I’m sending from a sandbox? Will the behavior be different in production? Also, is there any trick to adding images to the text template being used for the HTML body? I added one, but it doesn’t go with the email. Thanks for any tips you can provide!

  3. George
    George says:

    Amazing to have Lightning Emails available in a flow – thanks. Am I right in saying that this currently doesn’t support custom object merge fields in the template email – can only be merge fields on the contact, user or lead object?


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply