cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ShadowTech
Post Prodigy
Post Prodigy

Exporting newly received email to certain SharePoint library based on the "from" field criteria

Hello,

 

Scenario:

 

When receiving a new email I want to export that email to a specific SharePoint library (Folder). There are multiple libraries (100+) to export to based on who the email is from (one folder associated per sender). I need to also automate the new filename (email). Libraries (folders) will already exist.

 

Thanks in advanced.

1 ACCEPTED SOLUTION

Accepted Solutions
Amanthaper
Responsive Resident
Responsive Resident

@ShadowTech 

Hi,

Here's an example of what I was referring to using a JSON compose action.

There is a single condition which will loop through the JSON schema and place the email in the one matched from the sender.

The condition is case-sensitive and I has to convert the JSON folder name and email From both to lower case just in case.

You can save the emails in either .eml or .msg format. They'll both work in Sharepoint.

PAUG_ParseforSPemails4.PNG

FLOW

PAUG_ParseforSPemails5.PNG

RESULTS

PAUG_ParseforSPemails6.PNG

 

Hope this helps,

Aman------------------------------------------------------------------------------------------------------
If my post helps you with your problem or answers your question, please mark it Solved or Answered. This helps anyone with similar challenges. If you like my response, please give it a Thumbs Up.
------------------------------------------------------------------------------------------------------

View solution in original post

14 REPLIES 14
v-alzhan-msft
Community Support
Community Support

Hi @ShadowTech ,

 

Do you want to save the email attachment to the sharepoint library? Or do you want to save the email to the sharepoint library?

 

For the from field, you could add the switch cases for all the possible email addressed as below:

1.png

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Problem with your solution is that there are 100+ different folders that these emails could get exported to depending on the sender. And yes the email itself not attachments. So I was looking at the export email connector which creates a .eml file. The main dilemma is exporting the email to the correct folder in SharePoint which could be 1 of 100. I really don't want over 100 cases.

Amanthaper
Responsive Resident
Responsive Resident

How do you determine to which SP folder the email should be sent?

Can the destination folder be determined from any data in the email?

I assume you can map each sender to a SP destination manually someplace.

Are you able to create a SP list or have access to a db? If so I can think of 2 ways to do this dynamically using a "lookup table" approach without any conditional actions. It would require 1-time grunt work to manually map all Senders<>Destinations in list or table like this.

 

Sender                |    Destination Folder

---------------------------------

mickey@myorg  |   Mickey's SP folder

minnie@myorg  |   Minnie's SP folder

Daisy@myorg    |   Daisy's SP folder

Goofy@myorg   |   Goofy's's SP folder

 

After the mapping's done your flow would reference the lookup table, read the Sender and dynamically send to the mapped destination folder.

Alternatively if SP or access to a db are unavailable you could compose a JSON array object within the Flow (still need to create all mappings manually) and do an internal lookup and send to the mapped destination.

I think both of these approaches would do the trick.

 

 

Cheers,

Aman

If you can use a sender address aaa@bbb.ccc as a folder name, you do not need to use cases at all.

For each ingoing mail scan all folders and compare the folder name with the sender address. If they are equal create a new unique name for eml file and save it to the selected folder.

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.

Do you have a sample flow or json that I can reference?

Hi @ShadowTech, no I haven't.

Try to implement it yourself.

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.
Amanthaper
Responsive Resident
Responsive Resident

@ShadowTech 

Hi,

Here's an example of what I was referring to using a JSON compose action.

There is a single condition which will loop through the JSON schema and place the email in the one matched from the sender.

The condition is case-sensitive and I has to convert the JSON folder name and email From both to lower case just in case.

You can save the emails in either .eml or .msg format. They'll both work in Sharepoint.

PAUG_ParseforSPemails4.PNG

FLOW

PAUG_ParseforSPemails5.PNG

RESULTS

PAUG_ParseforSPemails6.PNG

 

Hope this helps,

Aman------------------------------------------------------------------------------------------------------
If my post helps you with your problem or answers your question, please mark it Solved or Answered. This helps anyone with similar challenges. If you like my response, please give it a Thumbs Up.
------------------------------------------------------------------------------------------------------

@ShadowTech 

Sure. Just flesh out the below for your needs.
{
"Senders": [
{
"MailFrom": "dduck@atnypa.onmicrosoft.com",
"MailFolder": "Donald"
},
{
"MailFrom": "bbunny@atnypa.onmicrosoft.com",
"MailFolder": "Bugs"
}
]
}

@Amanthaper  

 

What values were you using in the expression for the "ToLower"?

 

Thanks in advanced.

Hey @ShadowTech 

Left: toLower(triggerOutputs()?['body/from']) - This is the from email address

Right: Tolower(items('Apply_to_each')?['MailFrom']) - email address in JSON

Since conditions are case sensitive I find it best to convert both emails being compared to lower case so nothing is missed.  

 

Cheers,

Aman

------------------------------------------------------------------------------------------------------
If my post helps you with your problem or answers your question, please mark it Solved or Answered. This helps anyone with similar challenges. If you like my response, please give it a Thumbs Up.
------------------------------------------------------------------------------------------------------

@Amanthaper 

 

Awesome! Did you have to add the sender email addresses to the "From" field of the "When a new email arrives" trigger? Right now the trigger is not seeing the new emails and firing off.

 

Thanks in advance.

@Amanthaper 

 

User error. I fixed it.

@Amanthaper 

 

Everything was working fine until I added a shared email address to catch all emails. I'm receiving an error when it trys to create the file now but really isn't indicating what the issue is. 

 

For the trigger email and export email connectors I have the shared email address as the account I'm using then my account for the SharePoint file creation connector. Is that the issue? Does the SharePoint credential need to match that of the email(s) connectors?

 

btw, I am also adding attachments to the file if that makes any difference.

 

Thanks in advance.

 

2.jpg

Resolve! Corrected some of my own mistakes.😉

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (3,846)