Saturday, May 22, 2021

Power Automate - Read Email And Save In SharePoint List

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-

  1. First of all, we will create a SharePoint list to store the email content. I had created a list named "OutlookEmailToSharePointList" as below-
  2. Now we will create flow in Power Automate. For this, we will click on Integrate >> Power Automate >> See your flows.

  3. It will open the Power Automate portal where you need to click on My flows >> New flow >> Automated cloud flow.

  4. 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.
  5. It will be created as below-
  6. Now, we will add Action to it. Click on "+ New step" and choose "Html to text (preview)" action.
  7. Now add the body tag in the body content of this action.
  8. 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.
  9. Now click on "+ New step" and choose Create Item (SharePoint) action. Provide the Site address and the SharePoint list we had created above.
  10. Now give the values to the columns.

  11. The important point to remember here is that we will use the output of "Html to text" action to pass in Body column.
  12. With this the content part is done. Now, what, if the email has attachments also?
  13. 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".
  14. 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. 😎




  15. Now click on "Add an action" and choose "Add attachment" action.
  16. 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.
  17. The values for "File Name" and "File Content" will be available from "Get Attachment (V2)". 
  18. This will update all attachment one by one in the SharePoint list item.
  19. 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-
  20. Click on "+ New step" and choose "Export email (V2)".
  21. Pass "Message Id", "Original Mailbox Address" as "Message Id" and "To" from dynamic content window (when a new mail arrives (V3))-

  22. Lastly, once again use "Add Attachment" action and attach the email to SharePoint list item.
  23. Let's test it.
  24. I am sending below mail to my email id, I had I created this flow.

  25. Wait for a couple of minute to get flow executed and get completed. Let's see the SharePoint list.
  26. Wow, the record is here.




  27. This way, we can save email to SharePoint with attachments.
  28. 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 !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.