Sending Emails with Flow

2020-07-12

A common steps to use in a Dynamics CRM workflow is Send email. This is pretty straightforward: in this single step you can define the sender, recipient(s), body and all other available fields of the email entity. The sent email will also be visible in the Timeline of the regarding record.

When I set out to replace the Dynamics CRM workflow with a Flow, my goal was to use an email template to send an email using dynamically generated activity parties. Also, the email had to be visible in the Timeline of the regarding record. Quickly it became apparent that this is less straightforward in Flow than I hoped for.

In short, the following steps have to be taken:

  1. Initialize objects for the recipient(s), sender and email.
  2. Initialize an array for the activity parties.
  3. Set the recipient(s) and sender objects.
  4. Append the recipient(s) and sender objects to the activity parties array.
  5. Set the email object using the activity parties array.
  6. Use the unbound action SendEmailFromTemplate.

The example Flow I created for this post looks like this:

Send Email with Flow overview Send Email with Flow overview

Let’s break down each step.

Initialize objects recipients, sender, email

The first thing to do is initialize empty objects for the recipient(s), sender and email. Note that these objects will be initialized empty because we will retrieve the values to set the objects later in the Flow.

Initialize objects Initialize objects

Initialize array activityparties

Because of the nature of the activityparty entity, an array needs to be initialized to hold the activity parties. In the following steps, the sender and recipients objects will be appended to this array.

Initialize array Initialize array

Set object sender and append to activityparties array

Now, let’s set the sender object and append it to the activityparties array by using the correct activity party type1.

Set sender object and append to activity party array Set sender object and append to activity party array

One thing to keep in mind is that you might need to use decodeUriComponent('%40') to display the @ symbol. The formula used to set the sender object is:

{
  "participationtypemask": 1,
  "partyid_systemuser@{decodeUriComponent('%40')}odata.bind": "/systemusers(UserID)"

}

Of course, replace UserId with the primary key of the System User you retrieved in an earlier step.

Bonus tip: if you always use the same sender, you can set the sender object directly at initialization.

Set object recipients and append to activityparties array

The recipients object is set and appended in the same way as the sender object, but differs in participationtypemask.

Set recipients object and append to activity party array Set recipients object and append to activity party array

Set object email

The sender and recipients objects are complete and appended to the activityparties array, time to set the email object!

Set object email Set email object

The formula is:

{
  "email_activity_parties": @{variables('activityparties')},
  "@{decodeUriComponent('%40')}odata.type": "Microsoft.Dynamics.CRM.email
}

Perform unbound action SendEmailFromTemplate

Finally, the email object is ready and we can use the SendEmailFromTemplate unbound action to send our email.

Perform unbound action SendEmailFromTemplate Perform unbound action SendEmailFromTemplate

More information


  1. Activity party types: https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/activityparty-entity ↩︎

Common Data ServiceFlow

A quicker method to map different option set values in Flow