How to Send Email when a File is Uploaded with Power Automate

Do you want to automatically send an email whenever a file is uploaded to a SharePoint folder?

A workflow will often require you to create a file such as a month-end report and notify your manager when the file is available.

This can be done automatically using Power Automate and the When a file is created (properties only) trigger from the SharePoint connector.

This post will show you how to create a flow that will send an email notification when someone uploads a file to your folder.

When a File is Created Trigger

This flow will use the When a file is created (properties only) trigger. This allows you to select a folder so the flow only gets triggered when a file is uploaded to that folder.

This will trigger the flow whenever anyone uploads any file to the chosen folder. But as you will see later, you can use trigger conditions to limit who or what type of file will trigger the flow.

When you are building the flow, you might notice there is a SharePoint trigger named When a file is created in a folder. This sounds like it is the correct trigger to use, but it’s been deprecated so make sure you use the When a file is created trigger.

  1. Add the When a file is created (properties only) trigger to your flow.
  2. Select the Site Address for the SharePoint site with the folder you want to create notifications for.
  3. Select the Library Name of the SharePoint library that contains the folder.
  4. Select the Folder in the library. This can be any folder within the library, but keep in mind any subfolders within this folder will also trigger the flow.

This example will only trigger when a file is added to the Reporting folder within the Files library.

Create the Email Body

Now that you have the correct trigger set up, you can create the email notification.

The best method is to create the body for your email notification in a separate Compose action.

The email body input area has an annoying bug that sometimes changes the input when creating links in the HTML editor.

<p>Hi John,</p>
<p>@{triggerOutputs()?['body/Author/DisplayName']} uploaded a new file named <a href="@{triggerOutputs()?['body/{Link}']}">@{triggerOutputs()?['body/{FilenameWithExtension}']}</a> to the reporting folder.</p>

The above email body is created with HTML and has dynamic content from the trigger to customize the email body with the name of the user that uploaded the file, and the file name, and includes a clickable link to the file.

Add a Compose action to your flow and you can copy and paste this into the Inputs and edit it as required.

📝 Note: Anyone that wants to view the file with the link will need access to the file or the folder it’s in.

Send an Email from Outlook

Now you can use the output of the compose action as the input to your email notification.

There are several email options you could use, but the most reliable will be the Outlook connector.

⚠️ Warning: The generic mail connector is sent from a shared email and IP address, so deliverability to the inbox will be less reliable since it depends on the use of other tenants.

  1. Add the Send an email (V2) action from the Outlook connector to your flow.
  2. Add the recipients in the To field.
  3. Add the Subject text to the action.
  4. Add the Output dynamic content from the Compose action to the Body input.

You can also make dynamic lists of email recipients or dynamic subject lines if needed.

When you upload any file, an email similar to the above will get sent to the people listed in the To field.

Only Trigger the Flow Under Certain Conditions

You may only want this flow to run and send notifications under certain conditions such as when a certain user uploads, when the file is of a certain type, or when the file name meets certain conditions.

This is possible using the Trigger Conditions option in the trigger settings.

  1. Click on the Ellipses icon in the When a file is created trigger.
  2. Choose the Settings option.

This will open the Settings menu. At the bottom you will find the Trigger Conditions options.

  1. Click on the Add button to create a new condition.
  2. Add your conditions expression. Note that all condition expressions will need to start with the @ symbol to indicate it is an expression to evaluate during run time.
  3. Click the Done button to save the condition.

You can create multiple conditions and these will use an AND logic during the evaluation. This means that all the conditions will need to be true for the flow to run.

It’s better to create a single condition and use the and() and or() logical comparison functions to build your desired logic. This way to can create OR logic in the condition.

The following common expressions will create conditions that only allow the flow to run when they are true.

Only Send Email when File Name Starts with Certain Text

@startsWith(triggerOutputs()?['body/{FilenameWithExtension}'], '<searchText>')

The above expression will check if the file name starts with the text <searchText>. The flow only runs when this expression is true.

Only Send Email when File Name Ends with Certain Text

@endsWith(triggerOutputs()?['body/{Name}'], '<searchText>')

The above expression will check if the file name ends with the text <searchText>. The flow only runs when this expression is true.

Only Send Email when File Name Contains Certain Text

@contains(triggerOutputs()?['body/{Name}'], '<value>')

The above expression will check if the file name contains the text <searchText> anywhere within the name. The flow only runs when this expression is true.

Only Send Emails for Certain File Types

@endsWith(triggerOutputs()?['body/{FilenameWithExtension}'], '<searchText>')

The above expression will check if the file name with the extension ends with the text <searchText>. For example, you can set the <value> as xlsx to only trigger the flow when an Excel file is uploaded to the folder.

Only Send Email when the File is Uploaded by a Certain User

@equals(triggerOutputs()?['body/Author/Email'], 'name@youraddress.com')

The above expression will check the user who uploaded the file and only run the flow if the user’s email matches name@youraddress.com. This is a safer option than checking the user name since the email will be unique for each user.

Conclusions

Getting Power Automate to automatically send email notifications when you create a file within a folder can help speed up the approval time in repeated processes.

The flow is fairly simple to set up and will also allow you to limit what files trigger the process by using the trigger conditions.

Have you used this type of flow in your work processes yet? Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!