Introduction
Users can be bombarded with incoming emails that often leave them distracted and unable to concentrate on a single task. Microsoft Power Automate can help with this problem by providing users with the ability to monitor the To, From, and Subject lines of emails and create an automated workflow to take actions based on conditions.
Trigger flows
Currently, four triggers are available for Power Automate flows. These triggers are from the Microsoft Office 365 Outlook Standard connector and can be used to monitor incoming email:
When a new email arrives
When an email is flagged
When a new email arrives in a shared mailbox
When a new email mentioning me arrives
Each trigger will monitor all incoming email of the folder that you have specified in the trigger. Your default inbox is one of those folders. You can make monitoring more specific by describing to whom the email was sent, whether anyone was added to the Cc line, who sent the email, a specific string in the subject, and if attachments were added.
Save metadata to SharePoint List
Metadata is defined as a set of data that describes and gives relevant information about other data. For example, as emails arrive to your Outlook inbox, you would primarily focus on the key metadata such as the To, From, Subject, and Body content. However, several other metadata items are available, such as Importance that can be captured for future use. Saving metadata simplifies your task of searching in the future.
If you want to only capture the metadata of specific emails, then you can use a combination of options that are already available to define that parameter. For example, you can trigger a flow if the email was sent only to you, if you're included on the Cc line in a specific group email address, and if the email subject contains the words 'monthly inventory report'.
You can save the metadata from the email to columns in a SharePoint list as a new item.
Metadata items that are currently available:
From – Mailbox owner and sender of the message.
To – Recipients of the message.
Subject – Subject of the message.
Body – Body of the message.
Importance – Importance of the message such as low, normal, and high.
CC – Recipients who receive a courtesy copy of the message for informational purposes.
BCC – Recipients who receive a blind carbon copy of the message, whose name and email address aren't visible to other recipients of the message.
Reply To – The email addresses that are used when you reply to a message.
Body Preview – Preview of the email message.
Message ID – Unique identifier of the message.
Internet Message ID – The message ID in the format that is specified by Request for Comments (RFC) or RFC 2822.
Conversation ID – The ID of the conversation that the email belongs to.
Received Time – Date and time when the message was received.
Attachments, Attachments ID – Add the attachments or the attachment ID.
Attachment Name- Provides the name of the attachment.
Attachment content - Provides the content of the attachment.
Attachments Content - Type - Indicates the type of content that the attachments have.
Attachments last Modified Date Time - Indicates the last date when the attachments were last modified.
Attachments Content ID - Provides the content ID of the attachments.
Has Attachment – Indicates whether the message has attachments.
Is Read – Indicates whether the message has been read.
Is HTML – Indicates whether the email body has an HTML format.
Attachments Size – The size, in bytes, of the attachment.
Save attachments to SharePoint document libraries
A SharePoint document library is an excellent place to save your email attachments. Those documents are then accessible from anywhere with internet access. With Power Automate, you can create a flow to monitor emails of your choice and then save their attachments to a document library.
From the Power Automate home page, select My Flows from the left hand navigation menu.
Select + New Flow and select Automated Cloud Flow.
Name the flow Save Attachments to Sharepoint.
Select the When a new email arrives (V3) Office 365 Outlook trigger.
The flow will open in the Power Automate New Designer. Save the flow and switch off the New Designer in the top right hand corner.
Select the trigger to review its properties. Set the Only with Attachments property to Yes.
Select + New Step, search for Get Attachment (V2).
In the Message Id field, select the Message Id property from Dynamic Content.
In the Attachment Id field, select the Attachments Attachment Id property from Dynamic Content.
In the Original Mailbox Address, enter the email address you used for the trigger.
Note
Adding the attachment information will automatically add the Get Attachment action in an Apply to each action. This means that each attachment will get saved to SharePoint.
Under the Get Attachment action, select + Add an Action, search for SharePoint and then select Create file.
Note
You may wonder why we need to create a file if the file already exists and we just retrieved it. SharePoint doesn't know about the Outlook attachment so we must use the Create file action and pass the attachment content from Outlook.
Select the Site address and the folder path of your SharePoint library.
Note
The folder path is for the library where you want to save the attachments.
Select the File Name field. Select Dynamic Content and search for Attachments Name. This property is from the output of the trigger.
Select the File Content field. Select Dynamic Content and search for Content Bytes. This property is from the output of the Get Attachments action.
At this point your flow should look similar to the following image:
Next, you'll need to confirm that the files have been saved successfully and, if not, then you need to be notified.
Inside of the Apply to Each loop and below the Create File action, select + Add An Action and add a Condition action.
On the left side of the condition, select Add dynamic content, select Expressions, and then add the following:
outputs('Create_file')['statusCode']
On the right side of the condition, add 403.
Down the If yes (true) branch, select Add an action and add a Send an email (V2) action.
Select the To field in the action. The Dynamic Content box opens. Select the To property from the outputs of the trigger.
Note
The error notification email is sent to the same email address that received the original email from which the attachment must be saved.
Now, when incoming emails have any attachments, the attachments are saved in the SharePoint document library. If an error occurs when creating the file for some reason, the email address will be notified via email. The Apply to Each action should look similar to the following:
Post the message on Microsoft Teams
When inquiry type emails are sent to a general address, you can create a Power Automate flow to monitor those types of emails and then copy them to a team in Microsoft Teams. This approach will help make the email content available to a wider audience and will expedite the response time and/or quality of the response.
Consider incoming emails, which are sent from a specific mailbox that is used to send notifications from a customer-facing form. You can use that email address in the To field. If all emails come with the same subject, then you can add that subject line in the Subject filter as well.
Outside of the Apply to each, select + New Step and then search for Teams.
Select the Post a message in a chat or channel action.
For Post As, select Flow Bot.
For the Post in field, select Channel.
Select the Team where you want to post the message.
In the Message field, add a combination of text and dynamic content. The dynamic content comes from the Subject and Body of the incoming email.
Congratulations! Now when an email is received with attachments, the attachment is stored in SharePoint and a message is posted to a Teams channel with the subject and body information of the original email. If an email is received that doesn't have any attachments, there's still a post to a Team. Here's an image of the final flow:
Feel free to expand upon this unit. For example, in the email body, you could add a link to the email's attachments in SharePoint.