How to Send an Email from Power Apps Answered

How to Send an Email from Power Apps Answered

Hey there, In this article we are going to see how power apps and handle email sending in various scenarios.

Example 1:

First Case assuming we need to connect to some database like MongoDB and collect a collection data in a dropdown in a form field and send it to a user as an email

Steps to Follow:

  1. Connect to MongoDB: Go to the "Data" tab in the left-hand pane and click on "Connections". Click on "New Connection" and select "MongoDB" from the list of connectors. Fill in the necessary details, including the server address, port, database name, and credentials.

  2. Create a data source: Once you've connected to MongoDB, you can create a data source by clicking on "New Connection" again and selecting "New Connection". Select your MongoDB connection and the collection you want to use as a data source.

  3. Add a dropdown control: From the left-hand pane, drag and drop a dropdown control onto your form. Set its "Items" property to the name of your MongoDB data source and the "Value" and "Text" properties to the fields you want to use for the dropdown values and labels.

  4. Add an email connector: Go to the "Action" tab in the left-hand pane and click on "Connections". Click on "New Connection" and select your email provider from the list of connectors. Fill in the necessary details, including your email address and credentials.

  5. Add a button control: Drag and drop a button control onto your form. In the "OnSelect" property of the button, add a formula that sends an email using your email connector. You can use the "Selected" property of the dropdown control to get the selected value and include it in the email message.

Here's an example formula that sends an email when the button is clicked:

Office365.SendEmailV2("youremailaddress@example.com", "Form Submission", "Dropdown value: " & Dropdown1.Selected.Value)

Make sure to replace ""(sender email) with your actual email address. When the button is clicked, the formula sends an email with the subject "Form Submission" and the body text "Dropdown value: " followed by the selected value from the dropdown control.

Once you've completed these steps, you should have a form that allows users to select a value from a dropdown control and submit it to trigger an email.

Can we send it to multiple users:

Yes, In the example I provided, the email will be sent to the email address specified in the formula, which is "". You can replace this with the email address of the recipient to whom you want to send the email. If you want to send the email to multiple recipients, you can separate their email addresses with semicolons, like this

Office365.SendEmailV2("recipient1@example.com; recipient2@example.com", "Form Submission", "Dropdown value: " & Dropdown1.Selected.Value)

Example 2:

How can I do the same if I have a template where in I have to fill in the data?

To fill in data from your form into an email template, you can use the "HTML Text" property of the email body in the formula. Here's an example formula that fills in data from the form into an email template:

Office365.SendEmailV2("youremailaddress@example.com", "Form Submission", 
"<html><body><h2>Form Submission</h2><p><strong>Name:</strong> " & TextInput1.Text & "</p><p><strong>Email:</strong> " & TextInput2.Text & "</p><p><strong>Dropdown value:</strong> " & Dropdown1.Selected.Value & "</p></body></html>")

In this example, I've used the "HTML Text" property to format the email body as an HTML document. The data from the form is inserted into the email template using concatenation with the "&" operator. The TextInput controls are referenced using their "Text" property, and the Dropdown control is referenced using its "Selected.Value" property.

You can modify this formula to fit your specific email template by replacing the HTML code with your own HTML template and modifying the concatenation to match the fields in your form.