E-mail Me button on page

From SharePoint Online you can trigger a flow by using a link or a button. Sometimes you want to include data with that trigger action. In this article I will show you how to retrieve the email address of the person who clicked the button in a Power Automate flow.

Inspiration

This question from anthonys123:

My thought was to create a flow in PowerAutomate so when a button is pressed it sends a pre-scripted email from the person pressing the button. The directive is to confirm that someone has reviewed the page.

Power Users Community thread: I need to add a button to a SharePoint page to send an email.

emailmebutton

Queries

The first challenge was how to include the data. I figured the best approach would be the When a HTTP request is received trigger action. This action allows a custom body JSON schema.

However, in this instance we would not be able to include the body unless we would use some code with a POST request, which I did not want.

Luckily, I found the Queries section of the GET request. You could add parameters at the end of your URL (&customparameter=value).

emailmebutton_flow_result

It is possible to retrieve that parameter value within the flow via an expression like:

@me special string value

The second part of the challenge was to retrieve the actual data to include into the GET request. In this example I had a look at the formatting syntax reference article. There is an interesting section in there with special string values.

I have used the @me string value before in the course registration with list formatting blog. This string value will evaluate to the email address of the current logged in user.

Another interesting one is the @currentWeb string value. This string value will evaluate to the absolute URL for the site.

Formatting

The third part was to create a button with List formatting. Be sure to check out PnP GitHub io which has a lot of great List Formatting examples!

For the column formatting configuration I decided to use button and a type of elements. With this it is possible to point to your cloud flow link via a href attribute.

With view formatting it possible to hide column headers and to hide the ability to select a row.

Great, these are all the components which we need. Let’s start building the solution!

Flow setup

The first big part is setting up your cloud flow in Power Automate.

Checklist before you start:
– This example uses a Request connector action which is part of a premium feature, make sure you have a license which covers this.

emailmebutton_flow

1. Add a When a HTTP request is received trigger action.

emailmebutton_flow_trigger

a. Select the GET method under advanced options
b. Copy the HTTP GET URL value, you will need it for the column formatting part.

2. Add a Get User profile (v2) action.
To retrieve the email for user who clicked the button.

emailmebutton_flow_getuserprofile

a. Add the expression from the code snippet below via the Expression editor to the User (UPN) field.

3. Add a Send an email (V2) action.

emailmebutton_flow_sendanemailv2

a. Use the Mail dynamic content field in the To field
b. Provide a Subject value
c. Provide a Body value. In this instance I also used the displayName of the user and the site address which is hosting this news post. I used the value from the code snippet below.

That is it for the cloud flow setup of this example.

List setup

The second big part is setting up your SharePoint Online List which will host your button.

1. Create a blank list in SharePoint Online.

createblanklist

a. Provide a Title value, I used Email me Button

2. Add one list item to the new List

a. Provide a Title value, does not really matter what this is

3. Apply column formatting to Title column

emailmebutton_columnformatting_title

a. Click on the Title Column > Column Settings > Format this Column
b. Copy/paste the Json from the code snippet below into the Format columns editor

c. Modify the href attribute value and replace “https://WhenarequestisreceivedGETurl” with your value from the Flow setup step 1b.
d. Click Save

4. Create a new view and format it

emailmebutton_viewformatting

a. Click Create new view in the view menu
b. Provide a view name, I used Single Button view
c. Select Show as List
d. Click Create
e. Select the View and click Format current view in the view menu
f. Copy/paste the Json from the code snippet below into the Format view editor

g. Click Save

That is it for the list setup of this example.

Page setup

The last part is setting up your SharePoint Online page which will display the button.

1. Create a new page or news post

createnewspost

2. Add a list web part

listwebpart_config

a. Edit the page/news post
b. Add the List web part
c. Click Edit web part (pencil icon)
d. Select the list, Email Me Button
e. Select a View, Single Button View
f. Enable the Hide command bar toggle
g. Enable the Hide “See all” Button toggle
h. Click Apply
i. Remove the Title of the Web Part if needed
j. Publish the page/news post

That is it for the whole setup of this example.

Happy testing!

You may also like...

2 Responses

  1. Pierre-Yves says:

    Hello
    thank you for this post. I have some questions :
    In the “When a Http request is received” step, do you have to add some extra parameters to get the email address ?
    Where do you insert this text “triggerOutputs()[‘queries’][’emailaddress’]” ?
    Thanks
    Pierre-Yves

  2. Pierre-Yves says:

    OK I’ve understood ! There is no need to add extra parameter in the “When a Http request is received” step, It is in the formatting of the button that I need to add these parameters. I had just to follow all your example. I was confused because whne you decrible the flow, you already indicate to insert triggerOutputs()[‘queries’][’emailaddress’]” . So I was thinking some parametr had to be inserted in the first trigger of the flow. In fact it is only at the end of the post when you describe the button that I understood the parameter is inserted in the button !
    Thanks for your job

Leave a Reply

Your email address will not be published. Required fields are marked *

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