Showing posts with label Outlook. Show all posts
Showing posts with label Outlook. Show all posts

Friday, October 1, 2021

Power Automate: Send Mail With Other Account

 Hello Friends,

Welcome back with another post on Power Automate. Couple of days back, one interviewer asked me if we can send mail from Power Automate using mail account other than the creator of that Power Automate. I was not sure about that therefore I said that I don't know but as per my assumption, the person should be added as co-owner. 😞

Later on, I tried to find out if this could be possible. Surprisingly, I was correct but the answer was not complete. Because, first of all, the user should be co-owner. After then, in Connections, we have to switch the connection of outlook with that user's account connection. Let's try-

  1. First of all, create a simple list in SharePoint. I have created with name "SendOtherMail" having the default "Title" column.
  2. Now click on App Launcher (9 dots at top left corner) and click on Power Automate link.
  3. It will open the Power Automate portal. Click on + Create.
  4. Choose Automated cloud flow. Then provide a suitable name to the flow and choose trigger as When an item is created (SharePoint). Click on Create.
  5. It will create the flow and then ask you to choose the Site address and list name upon which it will work.
  6. Now add a step "Send an email (V2) Office 365 Outlook".
  7. Provide the input to the fields- "To", "Subject", "Body".
  8. If we execute the flow now, it will send email with the current owner capacity. But we want to send email from other account. So, we will save this flow as of now and will come back to it's details page by clicking on back arrow.
  9. Now click on Edit link of Owners section (#1 in below screenshot) to add a new co-owner.
  10. Search the new co-owner and add it.
  11. Then click on Manage Connections link in the Embedded connections section.
  12. It will load a page where all currently active connections will be displayed.
  13. If the added co-owner's outlook connection is getting displayed then click on ellipses (3 dots) ahead to that connection and choose Switch account. Otherwise click on + New connection link provided at the top and then choose Office 365 Outlook >> Create.
  14. It will the login credentials (Pick an account). Ask the user to provide credentials to create the connection.
  15. Once the connection get established, come back to the connections list.
  16. Look for the connection recently added and click on ellipses ahead of that connection. Choose Switch account from the popup list. When you click on Switch account, it will again show a popup where login accounts will be displayed. Choose the other user account.
  17. This way, outlook account has been switched.
  18. Now click on My flows >> Shared with me. As the flow has been shared with other user therefore, it will now appear in Shared with me tab.
  19. Click on the flow name and click on Edit.
  20. Expand the Send an Email action. Click on Show advanced options.
  21. Fill in the other user's email in From (Send as) input box and now Save the flow.
  22. Flow is now ready.
  23. Add an item in SharePoint list.
  24. Come back to Power Automate and check the Run history.
  25. As it can be seen that the flow has executed successfully.
  26. Now check the mail box.
  27. Hurray! The mail is received from other user's account. Now, if you ask the user to check his/her Sent Items in Outlook, he/she will find that the mail is reflecting in his/her Sent Items.
  28. This way, we can achieve this functionality.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

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 !