A new version (1.1) is available below. The attachment mechanism has been changed. The action now accepts a collection of Content Document Links, which are basically references to files that you’ve added to a record. If you’re working from a record, it’s easy to attach the documents that are part of it. If you need a general-purpose attachment mechanism, I suggest you create a special record on a custom object to serve as your defacto file store. You can add files to that store with the standard Flow File Upload component by passing the recordId into the component, and you can use a Get Records on Content Document Links (as shown in the video) to select the attachments you want to add.
If you want to pull an email address from an Email field, you can’t pass it directly to input attributes like SendTOThisOneAddress, but you can use this action to first convert the email into a simple text string.
Installation (See bottom of post)
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.
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:
- 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 Content Document Links. 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
Note that scratch orgs have a strict cutoff after sending just 50 email messages
If you’re interested in extending this class, please do so!
- 1.31 Unmanaged
1.2 Unmanaged (attachments are supported using Attachments instead of Content Document Links)
1.0 – Managed (requires Winter ’20)