cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KS3
Level: Power Up

Flow that automatically files emails to Sharepoint into a folder with the date backwards 190822

Hi, i would like to have a flow that automatically files emails with attachments to sharepoint. The action would be that an email is recieved, if it has an attachment, a folder is created at a designated location in sharepoint titled with the date backwards (190822) and the email and its attachment are separately filed into this new folder. 

If possible it would also be good to be able to filter this per sender of the email. Has anyone done something similar to this before, any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Flow that automatically files emails to Sharepoint into a folder with the date backwards 190822

Hi @KS3 this is a really cool Flow idea and I'll create a FlowBites video about this!

 

I've started with a "When a new Email arrives V2" trigger, which just runs on my Inbox. The one config item that I have changed, is that I changed "Include Attachments" from No to Yes. This is so I don't have to have another action later to go and get the attachments.

Flow Trigger.PNG

 

Next I have a couple of variables which I'll use as we go through the Flow. The first is going to be the name of the Folder which I want to create in SharePoint, and the second is the name EML file which will be our email. Both of them use expressions to format the Date/Time into the format that I want.

 

The expression being used for the folder is:

 

formatDateTime(utcNow(),'yyMMdd')

 

The expression being used for the file name is:

 

formatDateTime(triggerBody()?['receivedDateTime'],'hhmm')

 

Flow 1.PNG

 

Next I am going to use the "Create Folder" action which is part of the SharePoint Connector, point it my site and library, and then supply it with the name. The name will be the Folder Name variable which I initialized earlier.

Flow 2.PNG

 

Once I have the folder created, I'm going to use the "Export email (V2)" action from the Outlook for O365 Connector. This will grab the underlying source for the email which is structured as a .EML file. All I need to do is supply it with the Message ID of the email, which is dynamic content from the Trigger.

 

Now that I have the body of the email, I can use that to Create File in SharePoint. I will supply the action with the site, and then the Folder Path which I am using an expression for, the file name ("Email File Name" variable, with .eml appended to it) and then the File Content which is the Body of the "Export Email (V2)" action.

The Folder Name doesn't actually get returned in a easy format from the Create Folder action so you need to do some replacement on the identifier to replace the encoded characters:

replace(replace(body('Create_new_folder')?['{Identifier}'],'%252f','/'),'%2b',' ')

Flow 3.PNG

 

When I run the Flow up to this point, it will take my email and it will save the file within my SharePoint library.

 

Now we just need to break out and save the individual attachments. This is really easy because I selected Include Attachments from the trigger. So if I add another Create File action, and configure it with the same site and folder path, the only thing I need to do is supply the file name and content for the attachments. The File name will be the "Attachments Name" from the trigger, and the content will be the Attachments Content. By putting these pieces of dynamic content in, you will automatically have a loop put into your Flow to handle mutliple attachments.

Flow 4.PNG

 

Let me know how you get on with that

 





Did my reply help? Please give it a thumbs up.
Did I answer your question? Please mark my post as a solution!


Proud to be a Flownaut!





Community Leader: Black Country PowerApps & Flow User Group

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Flow that automatically files emails to Sharepoint into a folder with the date backwards 190822

Hi @KS3 this is a really cool Flow idea and I'll create a FlowBites video about this!

 

I've started with a "When a new Email arrives V2" trigger, which just runs on my Inbox. The one config item that I have changed, is that I changed "Include Attachments" from No to Yes. This is so I don't have to have another action later to go and get the attachments.

Flow Trigger.PNG

 

Next I have a couple of variables which I'll use as we go through the Flow. The first is going to be the name of the Folder which I want to create in SharePoint, and the second is the name EML file which will be our email. Both of them use expressions to format the Date/Time into the format that I want.

 

The expression being used for the folder is:

 

formatDateTime(utcNow(),'yyMMdd')

 

The expression being used for the file name is:

 

formatDateTime(triggerBody()?['receivedDateTime'],'hhmm')

 

Flow 1.PNG

 

Next I am going to use the "Create Folder" action which is part of the SharePoint Connector, point it my site and library, and then supply it with the name. The name will be the Folder Name variable which I initialized earlier.

Flow 2.PNG

 

Once I have the folder created, I'm going to use the "Export email (V2)" action from the Outlook for O365 Connector. This will grab the underlying source for the email which is structured as a .EML file. All I need to do is supply it with the Message ID of the email, which is dynamic content from the Trigger.

 

Now that I have the body of the email, I can use that to Create File in SharePoint. I will supply the action with the site, and then the Folder Path which I am using an expression for, the file name ("Email File Name" variable, with .eml appended to it) and then the File Content which is the Body of the "Export Email (V2)" action.

The Folder Name doesn't actually get returned in a easy format from the Create Folder action so you need to do some replacement on the identifier to replace the encoded characters:

replace(replace(body('Create_new_folder')?['{Identifier}'],'%252f','/'),'%2b',' ')

Flow 3.PNG

 

When I run the Flow up to this point, it will take my email and it will save the file within my SharePoint library.

 

Now we just need to break out and save the individual attachments. This is really easy because I selected Include Attachments from the trigger. So if I add another Create File action, and configure it with the same site and folder path, the only thing I need to do is supply the file name and content for the attachments. The File name will be the "Attachments Name" from the trigger, and the content will be the Attachments Content. By putting these pieces of dynamic content in, you will automatically have a loop put into your Flow to handle mutliple attachments.

Flow 4.PNG

 

Let me know how you get on with that

 





Did my reply help? Please give it a thumbs up.
Did I answer your question? Please mark my post as a solution!


Proud to be a Flownaut!





Community Leader: Black Country PowerApps & Flow User Group

View solution in original post

KS3
Level: Power Up

Re: Flow that automatically files emails to Sharepoint into a folder with the date backwards 190822

Great response, thank you @MattWeston365 . 

We used your structure and added in the first four letters of the senders domain name, and the first 20 characters of the subject line to create the folder name. 

Unfortunately the attachment export grabbed all the images from the email, rather than just the attached files, though works well other than that.

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (5,759)