This step-by-step tutorial outlines how to create a document and attach it to an email using the DocumentsCorePack custom connector for PowerAutomate (Microsoft Flow).
This flow is triggered on the update of a record (Account in our case), it then creates an Email using the “Create new Record” step from the common data services connector. Afterwards we are using our DocumentsCorePack custom connector to create an email body from a DCP Template and attach it to the email. Then we create an email attachment and attach it to the same email. The last step finally sends the email.
Figure 1: Overview of the Flow
When you create a new flow, you have to decide which action will trigger the flow. In our case we have simply added a trigger on the update of the Account.
Figure 2: Trigger
2. Create Email
In the second step we create an Email Message, you can leave the sender, recipient and regarding empty for now, as our DocumentsCorePack custom connector offers a very easy way to fill them later. You can still already fill the Subject and Description to your liking.
Figure 3: Create Email
3. Create Email Body
To create the Email Body, we are using the DocumentsCorePack custom connector and choose the step “Create Document Job (sync)”. In this step it is mandatory to specify a template which shall be used to create the email body, and an Entity ID with which the Template shall be merged. (NOTE: The template needs to be created for the Entity Type specified in the Email ID) To create the Email Body we must choose the Filetype “HTML”.
Figure 4: Create Email Body
4. Attach Email Body
After creating the Email Body, we need to attach it to the Email. For this we select the Document that was created in the previous Create Email Body step, this can be found under “Document (Base 64 Encoded)”. We also take the Filename from the previous step and the Email Message from the Create Email step.
Figure 5: Attach Email Body
Here you can see what the “Document (Base 64 Encoded)” looks like:
5. Create Attachment
In this step we want to create an additional attachment that shall be attached to the final email.
Again, we have to choose a Template, an Entity ID and an output FileType. As we want an attachment this time we are choosing “PDF”:
Figure 7: Create Attachment
6. Attach Email Attachment
Again, we have to attach the created document to the email. This time we select the “Document (Base 64 Encoded)” and the Filename from the Create Attachment Step. Additionally, we also need to fill Email ID with the “Email Message” from the “Create Email “Step.
Figure 8: Attach Email Attachment
7. Send Email
Now that the Email Body and Email Attachment are attached to our Email, we want to finally send the email. For the “Email To Send” we choose the “Email Message” from the Create Email step.
Based on the trigger you have chosen you can either use the “Owner” or “Modified By” user to get the current user, if you have a trigger that allows it you can also get the current user using the “User ID” from the dynamic values. This user can be specified as the sender of the email. For Sender (Schema name) we choose the Entity Type “User”.
Now we also have an option to specify the “Regarding” of the Email, for this we used the Regarding (Id) “Account” and the Regarding (Schema Name) Entity Type “Account”.
For the To-Recipient we have chosen the To-ID “Primary Contact” and the To-Schema name Entity Type “Contact”.
In Short: It is important that the “Schema name” points to the Entity Type of the ID that is specified.
Figure 9: Send Email
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to email@example.com