Customers with Marketing Cloud can use the Transaction Messaging API to send email, and this new SendEmailViaMC Flow Action enables Marketing Cloud customers to craft personalized content with flows before sending to email templates. This leverages the richness of Marketing Cloud email templates while providing a no-code way to do personalization.
In our demonstration here, we also add Salesforce CDP into the mix, and show how personalized emails can be generated that meld:
- Data from CDP profiles
- Data from web callouts driven by Apex invocable actions
- Data from core CRM records
Flow enables a lot of interesting combinations. In this demo, a Flow action calls out to a weather API and uses the results to recommend warm clothing in some email but not others. Flow also examines the salutation field of the CDP profiles and uses flow decision logic to decide which of several Marketing Cloud email templates to use.
Here’s the Flow that forms the core of the messaging personalization:
Two new invocable actions are available for installation as an unmanaged package.
SendEmailViaMC Flow Action
Example of Merge Field Usage:
|token||This authorization token is generated by Marketing Cloud. See ‘Authorization’ below.|
|toRecipient||an email address. Multiple recipients aren’t supported in this initial release.|
|contactKey||Unique identifier for a subscriber in Marketing Cloud. If you don’t provide an existing subscriber key , one will be generated at send time by using the recipient’s email address.|
|definitionKey||Note that this is a Transaction Send Definition that has to get created programmatically. You can attach this definition to a journey that has a Send Email action.|
|mergeKeys and mergeValues||These provide a way to pass up to 5 distinct merge values. If the email template specified in definitionKey has a merge variables that corresponds to a merge key, the corresponding value will be inserted into the email.|
|messageKey||A unique identifier used to track message status. If you do not pass one in, a timestamp is generated by the action and provided to the MC API. Note that this messageKey is then returned with the output if the send is successful. Can be up to 100 characters, and there are no restricted characters. Each recipient in a request must have a unique messageKey. If you use a duplicate messageKey in the same send request, the message is rejected.|
In the screen shot above, a specific token is pasted into the Send Email action. However, Marketing Cloud tokens only last 20 minutes, so this is not a deployable solution. Fortunately, it’s easy to generate tokens using the GenerateMarketingCloudToken Flow Action, also available in this package.
To generate tokens, follow the guidance here and generate a specific API Integration:
The token generation action requires the Client Id and Client Secret that you generate, along with the Authentication Base URI, which is custom to your MC instance. It also will require your accountId:
You can place this action immediately before your send to efficiently refresh your token on an as-needed basis:
Troubleshooting Authorization Issues
A couple of troubleshooting notes:
- Don’t forget to add the Authentication Base URI as a Remote Site Setting
- Make sure to use ‘Server-to-Server Integration Type
- When assembling the Authentication URL for the action, note that you have to append /v2/token, like so: https://mcgs269vcy2ztdsfpt5bjwv1mfl1.auth.marketingcloudapis.com/v2/token (if you don’t do this, you get a ‘596 Service Not Found’ return message)
You need to specify a specific
Merging Flow Values into Marketing Cloud Templates
Marketing Cloud users will be familiar with MC templates, which look like this:
The template shown here demonstrates simple string templates but also shows a merge field that interprets the incoming string as HTML.
If you go back to the example configuration of the SendEmailUsingMC, notice that mergeKey1 is ‘FirstName’. That matches the %%FirstName%% in the template above, so when the email is sent, Marketing Cloud will merge in the value of mergeValue1. In this case, that’s a record lookup. In the video, you’ll see that the record comes from a CDP profile, but it could also come from a CRM record.
The customized weather makes use of Flow’s own Text Template resource. Here’s the one that’s used in the sample flow:
Flow uses the Assignment element to conditionally populate WeatherWarning.