A common pattern is to use Power Automate to send automated emails. We may do this on a schedule or when something happens – for example, when an item is added or edited in a SharePoint list. But there may be circumstances where you’ll want to ignore Power Automate and send emails directly from Power Apps.
In this article, I’ll walk through all the properties and how to configure them in Power Fx.
Table of Contents
ToggleThe connector
For the purposes of this article, I’ll be using the Office 365 Outlook connector. In the linked documentation it lists all the available and deprecated actions. We’ll be using the Send an email (v2) action, recommended as what was V1 is now deprecated:
Ideally, you always want to use the latest version of an action. However, the original/deprecated versions are still available to use in Power Apps, so be sure to use the correct one.
You’ll need to add the connector to Power Apps in order to use it. With the app in edit mode, select Data. Search for, then add the Office 365 Outlook connector:
Sending an email will be associated with a Power Apps behavioural property of some kind. For example, OnVisible, OnSuccess or OnSelect. For the purposes of this article, I’ll be working with the OnSelect property of a button control.
The structure
As a reference point, we can see the Power Automate Send an Email (V2) action below:
There are a number of properties we can configure, some easier than others. We can see from Power Fx that they’re all available, but require a bit more work to get them operational:
In most cases, you’ll likely have what you need to configure most of these right away in your Power App. However, a couple of properties will require some additional configuration in Microsoft 365 Admin and Microsoft Purview. I’ll cover those in more detail when we get to them.
For now, we’ll start at the very basics and work our way up.
Bare minimum, single sender
The bare minimum to send an email in Power Apps is the same as in Power Automate. You’ll need the following to send a basic email: email address(es) to send it to, a subject and a body.
Let’s start with hardcoded text for each of those properties:
// Bare minimum to send an email from Power Apps
Office365Outlook.SendEmailV2(
// Email address
"bat.man@gotham.com",
// Subject title
"This is my subject title",
// Body
"This is an email body"
);
Bare minimum, multiple senders
If you’d like to include multiple email addresses, you can separate each one with a semi-colon:
// Bare minimum to send an email from Power Apps
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com;rob.in@gotham.com",
// Subject title
"This is my subject title",
// Body
"This is an email body"
);
Hardcoded entries are fine if the senders are always going to be static. Even then, a user email is still vulnerable to that person leaving so at worse case, a shared mailbox might be better.
Dynamic entries with basic body
Who we need to email from the Power App might need to be selected by the user. It might differ depending on circumstances, so ideally we’ll need a people picker. We can then take the email address(es) of the selected users and pass them into the Power Fx. Whilst we’re at it, we can use text input controls so a user can input their own email subject and body.
Our People Picker can be an active directory/entra lookup. For that, you’ll need to start by adding the Office 365 Users connector to your app:
Add a combo box control to the app. In the Items property, add the following Power Fx:
// Find user(s) based on search:
Office365Users.SearchUserV2({searchTerm: Self.SearchText}).value
Ensure that the DisplayFields and SearchFields properties of the combo box is set to [“DisplayName”].
Add 2 Text Input controls to the app, one for subject and the other for the email body.
To retrieve the selected users from the combo box, you’ll need to use the Concat function. We can specify a field for each user (we’ll need their email address) and a character to separate them each by (we’ll need a semi-colon). For the subject title and body, we can reference the Text Input controls directly, and their respective text output:
// Dynamic entries - simple body
Office365Outlook.SendEmailV2(
// Email addresses
Concat(cmbUsersDES.SelectedItems, Mail & ";"),
// Subject title
txtSubjectDES.Text,
// Body
txtBodyDES.Text
)
Dynamic entries with rich text body
The issue with using a Text Input control for the body is that you don’t have any formatting options. Sure, I can set the Mode property of the control to Multiline and type as I would normally:
But the output in Outlook doesn’t keep the line breaks. I also can’t apply other formatting such as bold, underline or different coloured text:
To get around this, simply replace the Text Input control with a Rich Text Editor control:
We can use the native formatting options in the control for our email body. These will be honoured in the outputs that land in Outlook:
The Power Fx is almost identical; simply referencing the HtmlText property of the rich text editor control for the email body:
// Dynamic entries - rich text body
Office365Outlook.SendEmailV2(
// Email addresses
Concat(cmbUsersDRT.SelectedItems, Mail & ";"),
// Subject title
txtSubjectDRT.Text,
// Rich text body
rteBodyDRT.HtmlText
)
Dynamic entries with HTML body
The rich text editor option will largely depend on user interaction. What if we wanted a customised, formatted output that’s build automatically, using data in the app? We can do just that by constructing custom HTML as a string for our email body.
Building a HTML body
A good place to start if you don’t know HTML is to use free online code builders, such as HTML Editor. You have two options in the tool:
1- Type the text as you want to appear in the right-hand box. It’ll automatically create the HTML for you on the left, OR
2- Type the HTML in the left-hand box to see how it’ll appear, using the right-hand box.
In the tool, a trick I like to do is indicate any parts that I’ll want to replace with something dynamic. I’ll usually indicate this with square brackets. I can also apply the formatting I’d like too, so it builds the correct HTML for me:
Before you can use the generated HTML code, you’ll need to replace double quotes with single ones. Copy & paste the output into a tool of choice (Word, Visual Studio, Notepad++) and do your Find & Replace All. You’ll then be ready to use the refined output as the input for an email body.
Usage in your Power App
To combine with dynamic entries (for example, variables or control outputs), I prefer to use string interpolation. It provides a cleaner way to join static and dynamic text. For the email body you’ll need:
1- a dollar sign
2- opening double quote
3- paste in your refined HTML
4- closing double quote:
We can then hunt down those placeholders (as shown with the green boxes above) and replace with our dynamic text. We need to bookend each entry with curly brackets:
Here’s the Power Fx snippet that supports the above:
// Dynamic entries with custom HTML body
Office365Outlook.SendEmailV2(
// Email addresses
Concat(
cmbUsersDCH.SelectedItems, Mail & ";"),
// Subject title
txtSubjectDCH.Text,
// HTML body
$"
Hi,
I am an email body, this is the
{txtSubjectDCH.Text} .
Thanks,
{User().FullName}
"
);
Here’s the desired email output, highlighted parts with the correct formatting and using data from the app:
CC and BCC
This is where we start deviating into some of the nested properties of the Power Fx structure. To, Subject and Body are the core fundamentals, any additional configuration lives within a nested set of curly brackets.
Starting simple, we can configure additional email address(es) for carbon copy (CC) and/or blind carbon copy (BCC). For the purposes of the Power Fx example, these are hardcoded email addresses. You can apply the same dynamic entries/people picker logic for these fields too.
/ CC and BCC
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with CC and BCC",
// Body
"Here is my email body",
// Add CC and BCC
{
Cc: "rob.in@gotham.com",
Bcc: "pen.guin@gotham.com"
}
);
If for some reason you’re unaware of how CC and BCC work, there’s plenty of articles on the internet to guide you.
Importance
An email can be sent with three levels of importance; High, Normal and Low. When configuring the Power Fx for the Importance property, these options will appear as intellisense options.
To send a High importance email:
// Importance
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with High importance",
// Body
"Here is my email body",
// Add Importance
{
Importance: "High"
}
);
To send a Low importance email:
// Importance
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with Low importance",
// Body
"Here is my email body",
// Add Importance
{
Importance: "Low"
}
);
The outputs to Outlook will indicate the selection made in Power Fx:
If you want to send an email with Normal importance, you don’t need to add the importance attribute to your Power Fx. The default state for all emails is Normal unless you state otherwise.
Reply to
An email directly from Power Apps will be sent from the logged-on user. If anyone clicks to reply to the email, it will automatically reply to the sender. Perhaps replies should be routed towards a central mailbox instead. We can use the Reply To property to encourage that.
In the Power Fx, we can directly specify the relevant email address for replies. In the example below, I want to encourage any replies to go to a central place instead of the originating sender:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with Reply To as Batman",
// Body
"Here is my email body",
// Add ReplyTo
{
ReplyTo: "The.Batcave@gotham.com"
}
);
From (send as)
You may have a scenario where all emails being sent from the app need to be sent as another user. Perhaps this could be a ‘No Reply’ account for an unmonitored email address, as the email is information only.
To action this, you’ll need a small amount of configuration in Microsoft 365 admin. You’ll need to do this whether using the property in Power Apps or Power Automate, so it’s a good tip to know.
M365 Admin
If you have access to your organisation’s Microsoft 365 admin centre – great. If not, you’ll need to find the right person who can help you set this up.
Your tenant’s M365 admin centre will be found at https://admin.microsoft.com/. When there, under Users select Active users:
Locate and click on the user account you wish to send emails on behalf of. In this example, that’s the No Reply ‘user’ which is an unmonitored mailbox for the company:
From the slide-out pane for the selected user, click on Mail then click on Send as permissions:
Find and add the relevant user(s):
As per the guidance on Microsoft Learn, this change can take up to 60 minutes for it to take effect.
Power Fx
Back to the Power App, we can now configure the From property. Simply add the relevant email address that’s been configured:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email as No Reply",
// Body
"Here is my email body",
// Add From (Send as)
{
From: "no-reply@gotham.com"
}
);
Emails will now show as being sent as the specified account:
Attachments
Attachments can be passed from a Power App to an email too! There’s a bit of a workaround to set it up but it’s absolutely possible.
I’m 100% sure there used to be a standalone attachments control at one point in Power Apps(?). If there was, it’s not there now. Attachment controls are only available in form controls that are bound to a SharePoint list or Dataverse table. It’s explained in the limitations here.
Let’s walk through the steps.
Datasource and form
In the app, add a connection to any SharePoint list. You can opt for any Dataverse table too, but that would mean the app is then a premium offering, so keep that in mind.
We aren’t going to be saving any data back to the chosen data source, it’s solely being added so we can access the attachments control. Here’s a random list I’ve added:
Next, add a Form control to your app and update the Items property to bind to the list/table you’ve just added. With the form control selected, you’ll need to access the Fields property from the property pane. Remove any automatically added fields and just leave the attachments control:
A key property to configure here might be the max number of attachments you’d like users to send. The Power Fx will look slightly different depending on whether you set the limit to 1, or greater than 1.
Power Fx
The attachment control acts like a table. Adding an attachment is essentially stored as a row in that table, with multiple columns. So we have to tailor our Power Fx to work with such a structure. We need 2 properties for files – the content and the file name.
To send a single attachment only, there’s a couple of approaches you can use. Firstly, with the Index function, where we take the first row from that table:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with attachments",
// Body
"Here is my email body",
// Add attachments
{
Attachments:
{
ContentBytes: Index(attachmentsControl.Attachments,1).Value,
Name: Index(attachmentsControl.Attachments,1).Name
}
}
);
Alternatively, you can use the First function that does the same thing:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with attachments",
// Body
"Here is my email body",
// Add attachments
{
Attachments:
{
ContentBytes: First(attachmentsControl.Attachments).Value,
Name: First(attachmentsControl.Attachments).Name
}
}
);
To send multiple attachments, you’ll need to use the ForAll function. This will loop through any possible attachments in the attachments control:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with attachments",
// Body
"Here is my email body",
// Add attachments
{
Attachments: ForAll(
attachmentsControl.Attachments,
{
ContentBytes: Value,
Name: Name
}
)
}
);
I always opt for the ForAll method. The requirement may only be a single attachment now, but if it’s increased in future, I don’t want to have to rewrite any Power Fx.
Sensitivity
Something becoming more common in organisations is sensitivity labels. These labels let us categorise and protect data. They’re set up through Microsoft Purview and can be assigned to emails, documents and more.
A group of sensitivity labels are provided out-of-the-box, but you can also build your own. As M365 users, we can then access and apply them accordingly:
We can apply a sensitivity label to an email when sending directly through Power Apps. The configuration is simple but there’s still a couple of need-to-know’s to get it to work. Don’t worry if you don’t have access to Purview as we can get the data we need via Power Automate.
Purview
Sensitivity labels are created and managed in Microsoft Purview. To access them, select Information Protection from the portal home page. You can also access via the Solutions option in the left-hand menu:
Next, select the Sensitivity labels option:
You can then select a label to show its properties. Here, I’ve selected the Highly Confidential – All Employees sensitivity label. We can see the scope includes email, it’ll apply a footer message and has the unique ID of the label. The latter is the key piece of information we need for our Power Fx:
Power Automate
You may not have the correct role in Microsoft 365 to access Purview and/or sensitivity labels. Instead, we can get the information we need using Power Automate.
To begin, create a flow with a manual trigger:
Next, add an action. Find and select the Send an email (V2) action within the Office 365 Outlook connector:
The irony. Writing an article about sending emails from Power Apps and we end up sending one from Power Automate 😆.
Configure the To, Subject and Body. This is going to be a one-off so it doesn’t matter on the content. At the bottom of the configuration pane, expand Advanced Parameters and select Sensitivity:
Select the sensitivity label you’d like the name/id for. I’ll use Highly Confidential\All Employees again:
Save and test the flow. Access the input parameters of the successful test and you’ll find the sensitivity label name/id:
Power Fx
Back to the Power App, we can now configure the Sensitivity property. Simply add the sensitivity label name/id you’ve retrieved, as a string:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.man@gotham.com",
// Subject title
"Send email with HC/AE sensitivity label",
// Body
"Here is my email body",
// Add Highly Confidential - All Employees sensitivity label
{
Sensitivity: "defa4170-0d19-0005-000a-bc88714345d2"
}
);
The email output will reflect the label and any of its configuration, such as watermarks, footers or whether the email can be forwarded:
Bringing it all together
I’ve broken down each property separately, but you can combine as many elements together in a single email. This will make your emails from Power Apps as informative as they need to be for recipients. Here is some example Power Fx that brings all the property config into one block:
Office365Outlook.SendEmailV2(
// Email addresses
"bat.ma@gotham.com",
// Subject title
"Send email with EVERYTHING",
// Body
$"Hi,
This is an email with
EVERYTHING! .
Thanks,
{User().FullName}
",
// Add everything!
{
Attachments: ForAll(
attachmentsControl.Attachments,
{
ContentBytes: Value,
Name: Name
}
),
Cc: "rob.in@gotham.com",
Bcc: "pen.guin@gotham.com",
ReplyTo: "The.Batcave@gotham.com",
From: "no-reply@hgotham.com",
Sensitivity: "defa4170-0d19-0005-000a-bc88714345d2"
}
);
You also combine email sending from Power Apps by detecting whether a recipient currently has an active out-of-office. I’ve covered this in a recent article if you want to know how this works in Power Apps.
Sending emails from Power Apps can be very useful in the right scenario. I hope the tips above will help with some of the configuration or art of the possible.
Thanks for reading. If you liked this article and want to receive more helpful tips about the Power Platform, don’t forget to subscribe or follow me on socials 😊.
Thanks for sharing, Craig. Very useful
Great tutorial Craig, step by step I can learn and apply. Thank you.