Blog
Email - Sending email attachments with the Office 365 Outlook connector
The syntax to attach files to an email message can be complex. This post describes how to use the Office 365 Outlook connector to send emails with attachments. It covers how to attach files from a SharePoint record, files that a user selects using an attachments control, images, audio recordings, and multiple combinations of files.
- How to attach files from a SharePoint record
- How to attach files from a file attachment control
- How to attach an image from the add picture control
- how to attach annotations/signatures from the pen input control
- how to attach audio recordings
- how to attach multiple attachments to an email
Attaching files from a SharePoint record
Let's suppose we take a SharePoint record with file attachments. If we add a card to a detail form, the syntax to add the file attachments to an email message looks like this:
Office365Outlook.SendEmailV2(
"timl@powerapps-guide.com",
"Email Subject",
"Email Body",
{
Attachments: RenameColumns(
ThisItem.Attachments,
"Value",
"ContentBytes",
"DisplayName",
"Name"
),
Importance: "Normal"
}
)
Attaching files that a user selects using a 'file picker'/attachments control
The first challenge is that there's no way to add an attachments control to a screen. The insert menu in Power Apps does not include this control. Therefore, the workaround is to copy an attachments control from a form that we've pre-built, based on a SharePoint or Dataverse record.
When we paste this control onto a new screen, we'll find various errors that relate to references that are no longer valid. We can use the app checker to quickly correct these errors. For each error that exists, we can delete the offending formula to clear the error.
Office365Outlook.SendEmailV2(
"timl@powerapps-guide.com",
"Email Subject",
"Email Body",
{
Attachments: RenameColumns(
attFiles.Attachments,
"Value",
"ContentBytes"
),
Importance: "Normal"
}
)
Attaching an image that a user selects using the 'add picture' control
A variation of the previous example is to build a screen that allows a user to choose an image from their local computer using an 'add picture' control, and to attach the selected image to an email.To carry out this task, we add an 'add picture' control to a screen. We can then use the formula beneath to send an email that includes the image that the user selects.
Office365Outlook.SendEmailV2(
"timl@powerapps-guide.com",
"Email Subject",
"Email Body",
{
Attachments: Table({
Name:"myImageName.jpg",
ContentBytes: UploadedImage1.Image
}
),
Importance: "Normal"
}
)
Attaching the contents of the 'pen input control' in an email
The pen input control allows users to make annotations or to draw images. We can send these annotations as an email image attachment, using a process that's very similar to the 'add picutre' control method.
Once we add a pen input control to a screen, we can use the formula beneath to send an email that includes the annotation.
Office365Outlook.SendEmailV2(
"timl@powerapps-guide.com",
"Email Subject",
"Email Body",
{
Attachments: Table({
Name:"myImageName.jpg",
ContentBytes: PenInput1.Image
}
),
Importance: "Normal"
}
)
Attaching an audio recording in an email
The microphone control allows users to make audio recordings. My previous post here describes this control, including how to save audio files to a data source.It's possible to attach an audio recording as an email attachment. To do this, we add a microphone control to the screen, and use the formula beneath.
Office365Outlook.SendEmailV2(
"timl@powerapps-guide.com",
"Email Subject",
"Email Body",
{
Attachments: Table({
Name:"myRecording.wav",
ContentBytes: Microphone1.Audio
}
),
Importance: "Normal"
}
)
Attaching multiple files in an email
Finally, a frequent requirement is to add multiple attachments from different sources to an email. An easy way to do this is to add the multiple attachments to a collection, and to pass this collection to the SendEmailV2 method. The formula beneath illustrates how to compose an email with files from an attachment control, and the annotation from a pen input control.
ClearCollect(colAttachments,
RenameColumns(
attFiles.Attachments,
"Value",
"ContentBytes"
),
{
Name:"myImageName.jpg",
ContentBytes:penSignature.Image
}
);
Office365Outlook.SendEmailV2(
"timl@powerapps-guide.com",
"Email Subject",
"Email Body",
{
Attachments: colAttachments,
Importance: "Normal"
}
)
Conclusion
- FormuIas - Is it possible to call a user-defined function recursively in Power Apps?
- Formulas - A beginners guide on how to create and call user-defined functions (UDFs)
- Formula - How to add a button that converts degrees Centigrade to Fahrenheit and vice versa
- Formula - How to convert a single delimited string to rows and columns
- Data - How to group data in a gallery and calculate sums
- Formula - How to calculate compound interest
- Utilities - The best way to peform OCR on images of Power Apps Formulas
- Example - How to use a drop down control to convert currencies
- Formula - How to parse JSON in Power Apps- 4 examples
- Data - How to get a row by ordinal number
- Formula - What to do when the If statement doesn't work?
- Formula - Boolean And / Or operators - What is the order of precedence?
- Controls - How to set the data source of a Combo Box to a comma separated string
- Numbers - 10 examples of how to round numbers
- Formula - Difference between round, square, and curly brackets
- Top 3 highlights of upcoming enhancements to the Power Apps language (Power FX)
- Formula - What to try when numbers don't format correctly
- Controls - How to convert HTML to Text
- Formulas - how to return all days between two dates
- Formula - How to create comma separated (CSV) list of items
- Formula - How to use the IF and Switch functions - 3 common examples
- Location - Finding the closest location and and sorting records by distance, based on the current location of the user
- Formulas - How to cope with weekends and public holidays in date calculations