The Power Platform Chap

Benjamin Crowe

Power Apps – Sending Outlook Emails in Canvas Apps

Introduction

361.6 billion! This is the amount of emails estimated to be sent daily during 2024. As you can see, sending emails happens often. Email is a great way to communicate across a business, not only to ask a question but also to notify an individual or team. In this post, I’ll walk through how to send an email from a canvas app.

Creating the Emailing App

The first step is to create a Canvas app for our users to send emails. In this example, I’ll put together a simple contact app, allowing users to ask questions via email to a selection of individuals.

Power Platform Canvas app designed to capture information from the user to then send as an email.

First, let’s break down what I have included in the app if you want to follow along with this post. I have added a combo box to store the recipient’s email address, two text inputs for the email subject and content and a button to submit the email.

So now we have an application that users can use to select their recipient, add a subject and write the body of the email, what do we need to add to make the submit button work and send the email?

Sending an Email

To be able to send an email from the app, you will need to include the Office365Outlook connector in the application. The quickest and easiest way to implement sending emails from a canvas application is with three text inputs and a button. Firstly you will need one for the recipient’s email, one for the email subject, one for the actual email content and finally a button to call the Office365Outlook.SendEmailV2 function.

Now that we have the app, we can look into how we use it to populate and send emails. To achieve this we add the following code to the on select element of the ‘Submit’ button.

Let us break down what the code is doing:

Office365Outlook.SendEmailV2(. . . . .

This calls the connector’s send email function. To send an email we need to include, the recipient’s email, a subject and the email content. To add the email address to the function, simply get the value entered into the txtToInputEmailScreen with the following code:

...
  txtToInputEmailScreen.Text //Recipents Email
...

The next two arguments contain the email subject text and main body content of the email:

. . . 
  txtEmailSubjectEmailScreen.Text, //Subject of email
  txtEmailBodyTextEmailScreen.Text //Body text of email
  )

When we put them all together the code looks like this, when the user clicks the submit button a standard email is sent to the selected recipients.

Office365Outlook.SendEmailV2(
        txtToInputEmailScreen.Text,
        txtEmailSubjectEmailScreen.Text,
        txtEmailBodyTextEmailScreen.Text
)

And if by magic here is the email received, by our test email account:

Sending To Multiple Email Addresses

It is also possible to send an email from a canvas application to multiple emails. To achieve this we need the help of the Concat function, with this function we can create a string of all of the selected email addresses separated by a semi-colon.

. . . Concat(
  cmbToSelectorEmailScreen.SelectedItems,
  Mail&";"
), . . .

This concat function replaces the txtToInputEmailScreen.Text and looks like below. When the user clicks the submit button a standard email is sent to the selected recipients.

Office365Outlook.SendEmailV2(
  Concat(
        cmbToSelectorEmailScreen.SelectedItems,
        Mail&";"
        ),
        txtEmailSubjectEmailScreen.Text,
        txtEmailBodyTextEmailScreen.Text
)

Add Cc and Bcc

Emailing multiple people is a great way to share a message, request or feedback. Though most of the time you’ll want to direct an email at a particular person, whilst keeping a wider audience in the loop, either using the Cc or Bcc.

Not a problem, we can accommodate this when sending the email. Firstly let us add the ability to include Cc and Bcc email addresses. Now let’s update the code so that we can use these new inputs.

To implement sending Cc and Bcc we will need to add the following code to our on select action.

..{
  Cc: txtEmailCcEmailScreen.Text,
  Bcc: txtEmailBccEmailScreen.Text
  }
)

So the final code for adding Cc and Bcc is this:

Office365Outlook.SendEmailV2(
  Concat(
        cmbToSelectorEmailScreen.SelectedItems,
        Mail&";"
        ),
        txtEmailSubjectEmailScreen.Text,
        txtEmailBodyTextEmailScreen.Text,
        {
          Cc: txtEmailCcEmailScreen.Text,
          Bcc: txtEmailBccEmailScreen.Text
        }
)

This is great for including a single email address, if you want to include multiple email addresses in Cc or Bcc, change the text inputs for combo boxes and use the same code as we did earlier for sending to multiple recipients. Like this:

..{
  Cc: Concat(
        cmbEmailCcEmailScreen.SelectedItems,
        Mail&";"
        ),
  Bcc: Concat(
        cmbEmailBccEmailScreen.SelectedItems,
        Mail&";"
        )
  }
)

Conclusion

I hope you enjoyed this quick how-to guide on sending emails via a canvas application. Though by no means is this an exhaustive guide is so much more you can do with this connector, from formatting the look of the email using HTML, deep links to records and sending attachments; to name but a few. I’ll have to make a post in the future covering how to do all that.

If you don’t use Outlook then never fear there are plenty of connectors you can use from third-party email providers, though the usage of those is outside the scope of this post.

If you have any questions feel free to leave them in the comments and I’ll try my best to answer them.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.