top of page

Recent Posts

Archive

Tags

Create and Send Emails with Attachments in D365/Dataverse with Power Automate

Jul 1, 2021
4 min read



Carrying on with my last post on Word Templates, I wanted to cover how to take a Word Template, or any file for that matter, create an email and add this as an attachment. With Power Automate, you can connect to over 300 connectors, including the Outlook connector that can send emails, which is great. However, if you are used to working with Dynamics 365 or Dataverse, one of the key advantages is tracking emails, and if you use the Outlook connector, you cannot do this. This post will show how to create an email, how to add an attachment and how to send an email, so that it’s tracked inside of D365/Dataverse.


Create a file or attachment that you want to add onto an email, in my example, I'm going to carry on from my previous post about Word Templates.





Then we will "Add a new row" using the Dataverse Connector and the Table name will be Email Message. This will create an email record/row in D365 which requires certain parameters.





Firstly, the way email fields to, cc, bcc and from work in D365/Dataverse is via what is called an activity party list. This is a list of rows/GUIDs of rows inside of D365/Dataverse that the email message is connected to. This is similar to a lookup, so when you look at the record in D365/Dataverse, you will be able to click on the link and be taken to that row.


You can use the fields “Activity Party Attribute” and “Activity Party Value” in here to build up the array you need for the party list, the first drop down “Activity Party Attribute” will ask if the person will be to, from, cc or bcc, you can choose one of these.





Then for the value, we need to full entity set name and value so contacts(f9340ebb-b1f1-e911-a812-000d3a49e7e9) and put it into this field. This will work for any email enabled tables, so contacts, system users and any custom tables that have been enabled for email and contain an email field.





If you switch to the array input you can see how the array is created/formed.




[
  {
    "participationtypemask": 2,
    "partyid@odata.bind": "contacts(f9340ebb-b1f1-e911-a812-000d3a49e7e9)"
  }
]

The ability to use an array here means that you can build a party list dynamically and create as many people in the to, cc or bcc that you like with a variable and loops. We’ll cover that in a future blog post.


You’ll notice the code above has what’s called the participationtypemask and the number defines where the email address for that party goes in the email, from, to, bcc etc.


Next we need to create the attachment for record/row that we will attach to the email. Select the Dataverse connector and the Add a new row action, for Table Name choose “Attachments”. Now we need to do a few unusual things to create this record, the first being we need to enter a formula for the Attachment (Attachments) field. This is because it’s the unique identifier for the attachment row, but also a required field. Usually Dataverse will handle the creation of the GUIDs, but you can override them, this is especially useful when doing migrations.


In this field just enter the function Null and as long as that function is in the field, Power Automate will allow you to save, and Dataverse will take care of creating the GUID. Then we need to specify the entity. I tried both of the options in this dropdown, but neither worked. The name of the entity we want to create the attachment associated with is Email Messages, so looking at the Metadata Browser, the entity name is lowercase email, so we put in a custom value for this field of email.





We need to set the lookup from the attachment to the email record we created earlier, again back to the Metadata Browser to find the EntitySetName which is emails, so we can put that in for the Item (Email Messages) field with the ID of the email we created in the Create an Email step.


For the Body of the attachment, we need to use the Base64 function to convert the file to something Dataverse can understand. We can use the output from the Populate a Microsoft Word Template step from my old flow, we don’t need to create a file in OneDrive for Business or SharePoint, we can just directly use the output from the Word Connector:


base64(outputs('Populate_a_Microsoft_Word_template')?['body'])

The other fields we need to fill in are File Name, which we can specify to be anything we wish as long as it’s got the right extension, and Mime Type but we get this from the Create Email step.





Now that we’ve created the Word template, created the email, created the attachment, the only thing left to do is send the email. For that, Dataverse has a “bound action” called “SendEmail” that will...send emails. Choose Perform a bound action from the Dataverse connector, table name is Email Messages, Action is SendEmail, Row ID is the email we created a couple of steps ago.





And that’s it, how to create attachments on emails via the Dataverse connector.







Ciao for now!

 
 
 

8 Comments


DanielReed
Oct 09

https://aussicasino.com came to mind while reading about tracked emails in Dataverse, since reliable automated notifications depend on getting recipient data right, whether it’s a CRM workflow or a casino account message. The explanation of activity party lists, especially participationtypemask and partyid@odata.bind, made that array much less mysterious, and I’ve hit the exact Outlook connector problem where an email sends but never appears in D365 history. The attachment GUID requirement also sounds like the kind of thing I’d forget and then spend an hour debugging.

Like

Unknown User
Unknown User
Sep 20

The activity party list part was always confusing to me until I read how you build it with party attribute and value fields. I also used War of Genesis: Idle Loot Wiki to check the email setup steps. Nice to see a tracked email option instead of the Outlook connector.

Like

Unknown User
Unknown User
Sep 07

The trick with activity party lists always trips me up, so seeing the exact fields to fill in helps a lot. I also tried the Outlook connector before realizing it won’t track emails in D365, which makes this Dataverse method way better. Meowdoku is a handy tool I found for testing similar flows.

Like

Unknown User
Unknown User
Sep 07

I tried this last week for tracking email attachments in Dataverse, and the activity party list part tripped me up until I mapped the GUIDs correctly. Krillion came up in my search for a cleaner way to handle it, and the step-by-step here matched what finally worked.

Like

Maureen Wankling
Aug 08

I was visiting my cousin and she had Connect Master open on her phone. I asked 'what is this?' and she handed it to me. Now I'm the one who needs help putting it down. Finding the hidden group of four is weirdly addictive in the best way.

Like

Matt Collins-Jones Blog by Matt. ©2026

bottom of page