Send An Email Notification Using Mail Connector In PowerApps

Introduction

 
In business scenarios where you don't want to call a Power Automate Flow from Power Apps to send an email or  push notifications, Microsoft has made our lives easier with connectors like Mail, Outlook.com, Office365Outlook, and so on. I am writing a series of articles where you will see how we can use these connectors to trigger emails directly to users' desired mailboxes or send a push notification to Power Apps using Power Apps Notifications/ Power Apps Notifications (V2) connectors. In this article, let's start with the Mail connector and understand the benefits and limitations along with a sample to simplify it further.
 

Mail Connector

 
It is important to understand that the Mail connector has 5 API calls per connection for 5 minutes and it can extend up to 100 API calls per connection for 24 hours. Hence, according to Microsoft documentation (see Reference section for the link to this documentation) Mail connector can be used to send infrequent emails. So with that said, while designing the email configuration within your application it is very important to understand the frequency of emails to be sent in your business use case. Mail connectors are not suitable for bulk email functionalities however can be used for minimal usage only. Sometimes there are cases where your business does not want to authenticate Outlook connectors, and Mail connectors come in handy then. Additionally, Mail connectors send emails from Power Apps (using microsoft@powerapps.com) and not as a specified person or the currently logged-in user who is triggering the email. 
 
Item  Description
Action in Power Apps  Send Email Notification (V3)
Operation ID
 SendEmailV3
Deprecated Operation ID  SendEmail
 
Understand the Action Parameters: Send Email Notification (V3)
 
Name  Key Required Type 
 To to  True string 
 To Names toname False string
 Subject subject True
string 
 Body text  True  html 
 Is Html ishtml  True  boolean 
 CC  cc  False string
 CC Names ccname False string
 BCC bcc False string
 BCC Names became  False string
 Attachment files  False byte
 Attachment File Name filenames False string
 
Syntax
  1. Mail.SendEmailV3(        
  2.  to,        
  3.  subject,         
  4.  text,         
  5.  ishtml,        
  6.    {        
  7.       toname:Text,         
  8.       cc:Text,        
  9.       ccname:Text,        
  10.       bcc:Text,        
  11.       bccname:Text,         
  12.       files:Blob,        
  13.       filename:Text    
  14.    }        
  15. )    
Sample: Send an email notification using Mail connector
 
To run through a sample, complete the below pre-requisites:
  1. Create a SharePoint list with Title, Description(Multiple lines of Text), isSendEmail(Yes/No, default- No) fields
  2. Create a Canvas app from blank
  3. Add SharePoint list created in 1 as a data source to the app
  4. Insert an Edit form and set its Default property to FormMode.New
  5. Insert a Button control and set its Text property to "Submit"
Refer to the below screenshots to validate the above points.
 
SharePoint List
 
Send An Email Notification Using Mail Connector In PowerApps
 
Canvas App Form
 
Send An Email Notification Using Mail Connector In PowerApps

Step 1
 
Now the main part of this article comes to light. Go ahead and add Mail connector to the data source as stated below:
 
Send An Email Notification Using Mail Connector In PowerApps
 
Step 2
 
Add the below code to OnSelect property of Submit button:
  1. SubmitForm(Form2);    
  2. If(    
  3.     DataCardValue6.Value,    
  4.     Mail.SendEmailV3(    
  5.         "YourEmailAddres",    
  6.         "Testing Email",    
  7.         "Email Body goes here",    
  8.         true    
  9.     )    
  10. );    
  11. ResetForm(Form2);    
where, 
  • DataCardValue6 is the isSendEmail boolean value on the form
  • Your email address - To email. Paste your email address here For eg: abc@gmail.com
  • Testing Email - Subject of the email
  • Email Body goes here - Body of the email (can be an HTML text too)
  • true - ishtml by default always set to true
Send An Email Notification Using Mail Connector In PowerApps
 
Step 3
 
Run the app and fill out the form details and click on Submit button. The app goes ahead and submits the form details to the SharePoint list and triggers an email.
 
Send An Email Notification Using Mail Connector In PowerApps
 
Notice the from the email it says Microsoft Power Apps and Power Automate <microsoft@powerapp.com>
 

Summary

 
We have seen an introduction to Mail connector and how it can be used in business applications, as well as the syntax format and a simple send an email on form submit.
 
References
  • https://docs.microsoft.com/en-us/connectors/sendmail/