Hello Friends,
Welcome back with another post on Power Automate. Today, we will try to read an incoming mail in Office 365 Outlook and then try to save the content of mail, it's attachment and the mail itself in SharePoint list. Let's start-
- First of all, we will create a SharePoint list to store the email content. I had created a list named "OutlookEmailToSharePointList" as below-
- Now we will create flow in Power Automate. For this, we will click on Integrate >> Power Automate >> See your flows.
- It will open the Power Automate portal where you need to click on My flows >> New flow >> Automated cloud flow.
- It will open the popup where you can choose the type of flow trigger "When a new email arrives (V3)", give the name of flow and click on Create button.
- It will be created as below-
- Now, we will add Action to it. Click on "+ New step" and choose "Html to text (preview)" action.
- Now add the body tag in the body content of this action.
- This will convert the Email body HTML content to plain text. Actually, the body content of an email is in HTML format containing header, span, paragraph tags. If we save the content as such, it will be complex to read. Therefore first we convert the HTML content to plain text and then we will save it in SharePoint list.
- Now click on "+ New step" and choose Create Item (SharePoint) action. Provide the Site address and the SharePoint list we had created above.
- Now give the values to the columns.
- The important point to remember here is that we will use the output of "Html to text" action to pass in Body column.
- With this the content part is done. Now, what, if the email has attachments also?
- For this, we will first get all attachments and update the recently create SharePoint list item by attaching those attachments. So, click on "+ New step" and choose "Get Attachment (V2) Office 365 Outlook".
- Now pass "Message Id", "Attachments Attachment Id" and "To". The moment you select "Attachments Attachment Id", you will see that "Apply to each" action will automatically appears and embeds to the flow. This is because the flow knows that they may be multiple attachments. 😎
- Now click on "Add an action" and choose "Add attachment" action.
- The Id here is the id of item created in SharePoint list. You will find this in "Create Item" section in the dynamic content window opened at right side.
- The values for "File Name" and "File Content" will be available from "Get Attachment (V2)".
- This will update all attachment one by one in the SharePoint list item.
- Now lastly, if you want to save the email (.eml) as well in SharePoint, then you need to first export that email and use Add Attachment action. Let's see below-
- Click on "+ New step" and choose "Export email (V2)".
- Pass "Message Id", "Original Mailbox Address" as "Message Id" and "To" from dynamic content window (when a new mail arrives (V3))-
- Lastly, once again use "Add Attachment" action and attach the email to SharePoint list item.
- Let's test it.
- I am sending below mail to my email id, I had I created this flow.
- Wait for a couple of minute to get flow executed and get completed. Let's see the SharePoint list.
- Wow, the record is here.
- This way, we can save email to SharePoint with attachments.
- If you wish add some filters upon the type of email you want to add in SharePoint, you can add those filter in the very first step "When a new email arrives (V3)".
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !