Category Archives: Logic Apps

Copy new Email and Details From Outlook 365 to SharePoint Online Document Library, Logic Apps: Mail Enable Office 365 SharePoint Online

Parent Post – Requirements and InformationCopy new Email and Details From Outlook 365 to SharePoint Online Document Library, Microsoft Flow and Logic Apps: Mail Enable Office 365 SharePoint Online

Related Post – Microsoft FlowCopy new Email and Details From Outlook 365 to SharePoint Online Document Library, Microsoft Flow: Mail Enable Office 365 SharePoint Online

How to create a Logic App to pass an email from Outlook 365 to a SharePoint Online Document Library

  1. Go to your SharePoint Online site
  2. Create a document library to receive the emails
  3. Go to portal.azure.com and login as the account you use to manage Azure
  4. Click New + at the top left
  5. Type in "Logic App", click "Logic App" in the Results
  6. Click "Create", enter the details for your Logic App
  7. Click Create
  8. Wait till the deployment is completed
  9. Navigate to your Logic App – you can do this by finding it under "All Resources" or clicking the notification message once deployment is completed
  10. Click on "Blank Logic App" under Templates
  11. Click "Office 365 Outlook" under connectors
  12. Click "Office 365 Outlook (When a new email arrives)"
  13. Click Sign in, log in with the email account you will be receiving emails to
  14. I've left most stuff as default, feel free to add any extra required filters. For the frequency, every time the "check for items" is run, you will be charged money. Doing it once an hour works out pretty cheap. Check out https://azure.microsoft.com/en-us/pricing/details/logic-apps/ for details on calculating costs. I have left 3 minutes for development. MAKE SURE you set "Include Attachments" to yes, or the attachments part will error
  15. Click "+ New step" and "Add an action"
  16. Type in "Content Conversion" and click on "Content Converstion – Html to text" – NOTE: we are adding this step as generally emails are in HTML and this shows as HTML markup when you add the Body of the email into a .txt file in SharePoint. Converting to plain text means we can add just the text and not HTML markup from the Body
  17. In the "Content" field, enter "Body" by double clicking the value "Body" under "When a new email arrives -> Body" as seen below
  18. Click "+ New step" and "Add an action"
  19. Search for SharePoint and click "SharePoint – Create file"
  20. Sign into SharePoint with the account that you will use to upload the emails. Don't forget about accounts with expiring passwords, you will need to come update the app when the password expires
  21. Enter the Site Address for your site collection or subsite, then select the Folder Path as your document library
  22. For the File Name we will enter the From field "_" and the utcNow() function. This will make the file name easy to identify by who it is from but also unique based on the utc date and time. You will find all of the email fields under "Dynamic content" and functions such as utcNow() under "Expression". Scroll down to "Date and time" section, double click on utcNow() which will enter it into the expression field, then click OK
  23. Ensure you type in ".txt" at the end of the file name. The type of file is not decided for you and .docx does not work (throws an error that it can't open the document)
  24. For the "File Content" field you can enter a mixture of dynamic and static content. I have entered a number of the email fields due to the fact that I can't assign these to metadata. Note that "Dynamic content" pop up box groups available information by the action it comes from, e.g. below we have "Html to text" and "When a new email arrives". You'll also notice there is a "See more" button which will show more hidden fields. You can also just search dynamic content and it will filter the list so you can quickly find values
  25. Below you can see what I have chosen for the File Content. Notice that I have used "The plan text content." from the "Html to text" group instead of the Body field
  26. Now we need to add any attachments from the email. Click "New Step" -> "Add an Action"
  27. Search for SharePoint and click "SharePoint – Create file". This will automatically log you into the same account used earlier for the first SharePoint step
  28. Enter the site URL and the document library. Under file name, click "Name (Attachment name)"
  29. This will convert your create file action into an "For each" action as it will need to loop through each attachment
  30. Let's make the "File Name" more useful, add the From field, "_ATT_" (to signify it's an attachment), utcNow() and Name field. When the item is added to the document library it should now look similar to the main email and group better, especially if you set your default view to sort by created date descending and then by File Name, you will be able to tell quickly that the email has attachments associated with it
  31. For the "File Content" field, enter "Content (Attachment content)"
  32. Your final attachment loop should look like the above
  33. Save your Logic App, you're now ready to test it!
  34. Click Run to start watching for emails (it will check on your trigger time set at the start, mine is 3 minutes)
  35. Create an email and add a couple of attachments. Send this to the email address you setup for the email trigger to watch
  36. It will take a few moments for the email to get picked up.
  37. Once it has successfully run, I can see my email plus two attachments in my document library
  38. If we open and view the txt file

Copy new Email and Details From Outlook 365 to SharePoint Online Document Library, Microsoft Flow and Logic Apps: Mail Enable Office 365 SharePoint Online

Related Post – Logic AppsCopy new Email and Details From Outlook 365 to SharePoint Online Document Library, Logic Apps: Mail Enable Office 365 SharePoint Online

Related Post – Microsoft FlowCopy new Email and Details From Outlook 365 to SharePoint Online Document Library, Microsoft Flow: Mail Enable Office 365 SharePoint Online

 

I've been working with a customer to figure out a way to email enable lists or libraries in Office 365/SharePoint Online. After deciding that a third party tool wasn't ideal, we looked at Logic Apps and Microsoft Flow. I found a few articles but they were out of date and not fully functional.

I'm writing this article to help fill the gaps until more funtionality is available for the SharePoint connectors and also to help clear up some of the things that took a bit of meddling to figure out. 

Here are the requirements and some comments on current restrictions. Restrictions apply to connectors for both Logic apps and Microsoft Flow as of 01/08/2017. If you are looking at this in September or beyond have a search around to see what Microsoft have implemented since this post. 


Requirement 1

Recieve an email to an email address. Once email received, it is picked up and processed into a document library

Comments

The reason we ended up using a document library instead of a list is currently there is no way to add attachments to a list item (this should come eventually), which means we can't add the BODY content as an attachment or the attachments in the email as attachments.

Ideally we wanted to grab the whole email, attachments and all and add the .msg file to the document library. This isn't possible (but also on the radar from Microsoft).

To work around this we will be creating a .txt file for all of the email details (from, subject, date received, has attachments?, body) and additional files for each attachment.

Requirement 2

Add metadata to the item for email fields

Comments

Sadly this isn't currently possible but it IS on the radar for development. You can only add metadata to a list item and not a document library. Adding metadata to list items also isn't ideal due to the fact you are restricted to 255 characters for string fields, not enough for the BODY content. 

For now the workaround is to pass all of these fields into the document we create in the document library.

I'll cover how to achieve this in both logic apps and flow, though both have pretty similar steps. NOTE: Flow is built ontop of Logic Apps, they are fairly similar but FLOW is accesable from SharePoint and more power user focused, where Logic Apps is more developer focused. 

Instructions for building mail enabled libraries in Office 365

I have split Logic Apps and Microsoft Flow into two seperate posts to reduce size

Logic AppsCopy new Email and Details From Outlook 365 to SharePoint Online Document Library, Logic Apps: Mail Enable Office 365 SharePoint Online

Microsoft FlowCopy new Email and Details From Outlook 365 to SharePoint Online Document Library, Microsoft Flow: Mail Enable Office 365 SharePoint Online

Other notes

I noticed over night that random spam from Microsoft processes made it's way into my document library. You may want to trigger the email received action based on a specific folder and route emails that match criteria to the folder.