Sending email when a form is submitted is an often mentioned requirement. One would perhaps think that Azure Logic Apps (or Microsoft Flow) would be needed for this, but this is not the case. A PowerApp (an app created with PowerApps) is able to send emails too.
Office 365 Outlook
When adding the Office 365 Outlook
connection, emails can be send with either one of the two following actions:
- Office365.SendEmail
- Office365.SharedMailboxSendEmail
The first option is mostly used.
Office365.SendEmail
By default, an email is sent as the person using the PowerApp.
When using the property From
, one can also send an email as, or on behalf of, another mailbox. This does require specific permissions (Send As/Send on Behalf) for the person using the PowerApp on that mailbox. Having full access to the mailbox is not the right permission. When omiting the property Importance
, a low importance is used.
Below are examples of this action.
Send
Office365.SendEmail("rick@contoso.com", "Subject", "Body")
Send As/Send on Behalf
Office365.SendEmail("rick@contoso.com", "Subject", "Body", {From:"someoneelse@contoso.com"})
Office365.SharedMailboxSendEmail
One needs to have access to the shared mailbox to be able to send emails from it. An Office 365 Group mailbox is not a shared mailbox.
Below is an example of this action.
Office365.SharedMailboxSendEmail("sharedmailbox@contoso.com","rick@contoso.com","Subject","Body")
Where to insert the actions
Where to insert the actions depends on the way form information is submitted:
- Using an form control
- Using the function
Patch
The first option has two properties where sending an email makes sence:
- OnFailure
- OnSuccess
The second option (the function Patch) is a bit more complex and will be described in a future blog post about error handling.
HTML messages
The actions can send emails with a HTML body. CSS can be added too. This allows for good looking emails which can be set as a requirement by customers.
The way to sent a HTML email is not difficult. One just has to add another property: IsHtml:true
. When this property is ommited, the value IsHtml:false
is used. An example is given below:
Office365.SendEmail("rick@contoso.com", "Subject", "<b>Body</b>", {From:"someoneelse@contoso.com", IsHtml:true})