Categories
Dynamics 365

Sending HTML emails through Dynamics 365

Task: Send HTML email though Dynamics 365
Difficulty: Advanced
Time to implement: 1-2 hours

Check out this video

Tracking emails is a popular feature in Dynamics 365 Customer Engagement. You can track emails by connecting your mailbox with Microsoft Exchange and either use the Dynamics 365 app for Outlook or Dynamics 365 email capabilities to send out emails. Companies see great value in this feature because it allows them to have a CRM system in place where relevant interactions between a customer and an organization can be observed.

In this post, I am going to show you how to use the Dynamics 365 emails and discuss some of its benefits and limitations in terms of functionality. Dynamics 365 emails are equipped with a simple email editor for creating emails. The editor covers the basic requirements for what you would normally use when sending an email from your email client such as Gmail or Outlook.

Email editing experience in Dynamics 365

Dynamics 365 emails allow you to send emails to multiple recipients, add attachments, insert links and images. However, if you want to create your own HTML email you cannot do that through Dynamics 365 emails. This could be useful in scenarios where the company wants to send out a promotional emails, e.g. because there is a new product release or an event. Dynamics 365 does not support HTML emails.

On the other hand, if you like to send HTML emails through Dynamics 365 there is a workaround. By leveraging Power Automate and the Dataflex (CDS Current enviornment) connector, you can create a workflow that creates and sends an email with HTML content.

For example, you have a lead that you would like to send an event invite to. You can achieve this by creating a flow in Power Automate and use a field on the lead to trigger the flow. The salesperson could simply check a box on the lead form to send the invitation. Furthermore, the email would be automatically tracked in Dynamics 365. This gives the salesperson and her manager a better overview of who has received an invitation to an event.

In the remainder of this post I will show how you can create and send a HTML email through Dynamics 365 Sales with the help of Power Automate.

1. Create the flow

  1. You start by navigating to make.powerapps.com and create a solution for your Flow. For information on how to create a solution in Power Apps please refer to this article.
  2. Click on the ‘+New’ button and select Flow
Create a Flow from within a Power App solution
Create a Flow from within a Power App solution
  1. Search for and select the Dataflex ‘When a record is created, updated or deleted’ trigger (Common Data Service current).
  2. Give your Flow a name.

2. Configure the flow

Once you have created the flow you can define the entity name, the type of trigger condition as well as the filtering attribute for the newly created trigger. In this case we have created a custom field which will serve as the trigger for this flow or the filtering attribute.

  1. In trigger condition choose Update.
  2. In the entity name choose Leads.
  3. For the Scope select Organization.
  4. In the filtering attribute write the name of your custom field.
Dataflex 'When a record is created, updated or deleted' trigger (Common Data Service current)
The When a record is created, updated or deleted trigger (CDS current)

Next we need a variable to store our HTML. To do this we:

  1. Click on the ‘New Step’ button.
  2. Select Initialize variable.
  3. Give our variable a name and choose type string. Leave the value field empty.
Power Automate Initialize variable
Initialize variable

Before we set the variable you first want to check if our field value meets the condition.

  1. Click on the ‘New Step’ button.
  2. Select control.
  3. Choose control condition.
  4. For the condition choose the custom field and that it should be equal to ‘true’. The field is a two option field which can be either true (1) or false (0).
The condition should be that send invitation value is true.

When the condition is true you want the email to be sent. First you need to set the variable we created in our previous step and then you will create the email. Lastly you want to send the email message using a bound action.

  1. In the ‘If yes’ box click ‘Add an action’.
  2. Choose Set variable.
  3. In the name select the variable you initialized in steps 2.6-2.7.
  4. In the value field paste in your HTML code.
Set variable and have it store the HTML code

Now you have created the condition and set the variable. This leads to the creation of the email message. To create the message you:

  1. Below the ‘Set email content’ action click ‘Add an action’.
  2. Choose Create a new record – Dataflex (Common Data Service current).
  3. For the email message choose the sender and receiver of the message. You must refer to the entity’s path as shown in the following screenshot. For more info about how this connector’s attributes are referenced see this article.
How lookup fields are referenced in the create a new record current action
How lookup fields are referenced in the create a new record current action
  1. Click ‘Show advanced options’ and add the email body to the ‘Description’ field, owner in the ‘Owner (Owners)’ field, the lead (‘/leads/{the lead GUID value}’) in the ‘Regarding (Leads)’ field, and the subject in the ‘Subject’ field.

The final step is to send the email. This requires a special kind of action called a bound action. To see the difference between bound and unbound actions please refer to this article.

  1. Below the ‘Create a new record’ action click ‘Add an action’.
  2. Choose Perform a bound action – Dataflex (Common Data Service current).
  3. In the Entity name choose Email Messages
  4. For the Action Name choose SendEmail.
  5. In the Item ID insert the Email Message ID. You find the ID by using the dynamics content and choosing the unique ID of the email message you created in steps 2.16-2.19 above.
  6. In the IssueSend select Yes.
Perform a bound action - Dataflex (CDS current) trigger
Perform a bound action – Dataflex (CDS current) trigger

3. Test the flow

You can now test your flow to see if everything works as it should. Do a test run on a lead in your Dynamics 365 Sales to verify that the flow runs when the custom field is changed on the lead and if the email is sent when the flow condition is true. For more information about performing the test, please refer to the blog post’s video above.

By Illugi Hjaltalín

Consultant and blogger. Always on the look out for smarter ways to perform work related tasks leveraging digital technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s