Power Automate: Send an email using the Email Template – Part 2

Sending
User Review
0 (0 votes)

Introduction

In our last blog, we saw how we could create Power Automate Flow to send an email using the Email Template. We used “SendEmailFromTemplate” action to send a single email.

Now, in this blog, we will see how we can send bulk email messages using the Email Template.

Let us say, we want to send emails to reconnect with all our contacts in the system that we have not been in contact with for a while.

Below is how we can achieve this using the Power Automate. This could help you to create Power Automate Flow for your requirements where you may want to send bulk email messages.

Setup trigger for the Power Automate

For this example, I have used ‘Manually trigger a flow’ trigger.

Send bulk emails using the Email Template

Retrieve Email template

We will add ‘List Records’ step of Common Data Service Connector (Current) to retrieve the Email Template by its name (Title). We are retrieving the ‘Contact Reconnect’ template.

Send bulk emails using the Email Template

Add filter query to retrieve template by the title as shown below

Send bulk emails using the Email Template

This step will return the “Contact Reconnect” template. We will need this GUID of the template in the next step.

Retrieve records for which we want to send email

I am retrieving contacts from the system which I want to reconnect.  We will add ‘List Records’ step and will retrieve contacts.

Send bulk emails using the Email Template

Initialize variable and store array of record’s GUID

As we want to send separate emails to each individual contact, we will first store GUID’s of each contact in an array variable.

First, initialize the array variable

Send bulk emails using the Email Template

Then, loop through all contacts retrieved in the above step and append GUID’s of each record to the array.

Send bulk emails using the Email Template

Retrieve Sender for the email

Sender of the email must be the user in the CDS environment. We will retrieve the System User record using ‘List Records’ step. We will use GUID of the user record in the next step.

Send bulk emails using the Email Template

Use ‘SendTemplate’ action

This ‘SendTemplate’ action is used to send bulk email messages using the Email Template. To execute this in Power Automate we need to add “Perform an unbound action” step.

This step requires below parameters,

Action Name: Select ‘SendTemplate’ from the list of actions.

TemplateId: GUID of the Email Template. In the second step, we retrieved the email template, we can use following expression to get the GUID of the template. first(body(‘GetEmailTemplate’)?[‘value’])?[‘templateid’]

Sender: Entity object of the user. Need to pass in the following format, systemusers(<guid of user>). To read the guid from the ‘List Records’ step, I can use following expression, first(body(‘GetSender’)?[‘value’])?[‘systemuserid’]

Recipients: Here we need to pass array of entity objects. I have passed the variable where I stored the list of entity objects of all the contacts. This parameter accepts value in the below format

Send bulk emails using the Email Template

Regarding: Record is to be set as the ‘Regarding’ of the email. In my example, setting the ‘Regarding’ does not make sense as I am not sending emails regarding any specific entity record. But, the problem is this parameter is required and it accepts entity object only. Here, I have passed the user entity object. As the user cannot be set as a ‘Regarding’, generated emails will not have regarding set.

Send bulk emails using the Email Template

This is all we required to send bulk email messages.

Now let us see what happens in the background. After we run the flow, a ‘Bulk Email’ system job gets created in the background. This job then creates and sends the email to all recipients separately.  We can check the status in the system jobs as shown below

Send bulk emails using the Email Template

If you have added 5 records in the Recipients then 5 separate emails will get sent to them.

Send bulk emails using the Email Template

This is how we can send bulk email messages even for a large set of records.

Note: The SendTemplate action will not send emails to contact/account/lead if they opt-out for bulk email.

Send bulk emails using the Email Template

Conclusion

We can use Power Automate flow to send bulk email messages to a large set of recipients.

Reference: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/sendtemplate?view=dynamics-ce-odata-9

Leave a Reply