Sending emails via PowerApps triggers is a useful tool to send out notifications and reminders as you guide your users through a workflow. . It’s nice to be able to auto populate that email notification with data from wherever your data store is, and if its SharePoint you can also attach the list attachments as attachments in your email.

For example, imagine if an IT manager was using a SharePoint list as a backend for a PowerApp displaying IT tickets. They could upload screenshots of the issue to the list item and simply click a button to notify the recipient that the ticket is closed with any relevant screenshots attached.

The steps to attach a SharePoint list item as an email attachment via PowerApps are below:

Add a Data Connector to Office365Outlook

  1. Inside of your PowerApp, click on the View Tab and then select “Data Sources” from the menu
  2. Select “New Connection” from the modal that appears on the right
  3. Search for Office 365 Outlook and select it to add it to the PowerApp

Add the Control

Add whatever control to the form that will end up triggering the email send. Typically this ends up being a button, but an icon or almost any other control can be used. If you are using a button or an icon, go to the OnSelect action for the control, but theoretically emails can be triggered from almost anywhere in PowerApps so don’t feel restricted to a button or icon.

Enter the Code

Call the connector and function by entering:

Office365Outlook.SendEmailV2()

Add the “To”, “Subject”, and “Body” fields:

Office365Outlook.SendEmailV2(*To*,*Subject*,*Body*)

Now we can add the attachments. Essentially what we are doing is passing in the attachment content in bytes and enabling HTML in the email to tell the connector to convert those bytes to a file.

Office365Outlook.SendEmailV2(*To*,*Subject*,*Body*{IsHtml: true,
Attachments:ForAll(*Attachment location*,{Name:ThisRecord.Name,   
ContentBytes: ThisRecord.Value,   
'@odata.type': ""})}); 

For example, if there was a form on the PowerApp screen that we can reference with an attachment field either hidden or visible we could enter this into the *Attachment location* code above.

Office365Outlook.SendEmailV2(*To*,*Subject*,*Body*{IsHtml: true,
Attachments:ForAll(DataCardValue18.Attachments,{Name:ThisRecord.Name,   
ContentBytes: ThisRecord.Value,   
'@odata.type': ""})}); 

Summary

The above steps will allow you to send SharePoint list item attachments as attachments through an email in a PowerApps trigger.Working with attachments can get a little complex but this should be a fairly strait forward way of managing it. For more reading check out Microsoft’s documentation on the Outlook connector here.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *