cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
J4ck
Frequent Visitor

Email Body to CSV

Hi all,

 

I recieve an email that contains CSV text in the body of the email, I want to extract anything in the body of the email after "@@" and then convert this into a CSV table and then email this back to the same people that were CC'd into the email in the first place. I have tried many different things but always hit a road block! I'm quite new to powerautomate so apologies if this is a simple question.

 

Here is what my flow currently looks like, but i'm no where near the end as I keep getting stuck 😅😪

 

J4ck_0-1694465413413.png

 

J4ck_1-1694465422604.png

 

 

 

Many thanks,

2 ACCEPTED SOLUTIONS

Accepted Solutions
Jason79
Frequent Visitor

Hi @J4ck 

After the HTML to text I have done the following to remove all the text upto and inc. 2nd @ plus the headers:

 

Jason79_0-1694587796152.png

Jason79_1-1694587852872.png

I then did splitbycomma and JSON steps in this video: How to parse a CSV file with Power Automate - YouTube

Jason79_4-1694588734043.png

 

 

After JSON step I added Parse JSON action, click Generate from sample and then paste in 

{
"Heading 1.": "",
"Heading 2": "",
"Heading 3": "",
"Heading 4": "",
"Heading 5": "",
"Heading 6": "",
"Heading 7": ""
}

 

I then have an excel file with a table using these headers. I then added a add row into a table action, selected that file and added the dynamic content from Parse JSON

 

Jason79_3-1694588603616.png

 

Jason79_2-1694588210056.png

 

My result below

Jason79_5-1694588934436.png

 

You could then add an action to send that file via email.

Hope this is of some help.

View solution in original post

Jason79
Frequent Visitor

@J4ck 

Had another go but sending out a .csv file. Reiterate I'm a novice so there may be more smarter /efficient methods but I ended up receiving an email with a .csv attachment.

 

Re. my original post above. After and outside the apply to each add in below 

 

Jason79_0-1694599077917.png

 

Then add these steps

Jason79_1-1694599321393.png

Then add action to send email

 

Jason79_2-1694599450165.png

 

 

I utilised this: Instantly using Power Automate create CSV file and send email attachment - Global SharePoint Diary (...

 

I did receive email with email attachment which I haven't tried before 🙂

 

Jason79_3-1694599736023.png

 

View solution in original post

16 REPLIES 16
Sundeep_Malik
Multi Super User
Multi Super User

Hey @J4ck 

 

Can you provide how your email looks like? I might be able to give you some hints.

 

Also make sure the format is similar always because the email flows are hard coded and any change would result in failing of the flows.

 

Suggesting you some videos for email flows and also you can try using chat gpt for it.

 

https://www.youtube.com/watch?v=62BB3rpe37g

 

Using Chat GPT:

 

https://www.youtube.com/watch?v=l3YqVpRQniw

 

 

I hope this helps 🙂

Hi @Sundeep_Malik 

Many thanks for such a fast reply!

Please see the email format below, the only thing that would change would be the data within the CSV the rest of the format will stay the same including the headings.

Warning: This email is not from a known sender.

Please find attached\n ATTACHMENT=test.csv&SIZE=423789@@Heading 1.,Heading 2,Heading 3,Heading 4,Heading 5,Heading 6,Heading 7
60,Example,13,Example,Example,6.01,Example
64,Example,15,Example,Example,5.46,Example
21,Example,1,Example,Example,Example,Example
20,Example,4,Example Example,Example,Example

 

I'll check out your videos, but do let me know if you have any tips as I've been struggling with this!

 

Thanks

Sundeep_Malik
Multi Super User
Multi Super User

@J4ck 

I always struggle with email flows as well. Hehe.

Tagging a person who might be able to help:

 

@ManishSolanki 

 

He is good with the email flows.

I hope he will be able to help. 🙂

J4ck
Frequent Visitor

I've added some pictures of my flow incase that helps, I'm just getting stuck on extracting the data in the correct format at the moment.

Hi @J4ck 

 

I would request you to pls share the output of "Convert HTML to text" action (with sample data) so that I try some logic to extract data. Does the csv in email body has fixed columns? Do the rows are also fixed in number or may vary?

 

Thanks

Thanks
Manish Solanki
View my blog
Linkedin

Hi @ManishSolanki

 

Many thanks for looking into this, hopefully the above comment answers your questions, but to rephrase thats the output of the HTML to text, the CSV file has fixed rows (these will never change) however the rows will change.

Warning: This email is not from a known sender.

Please find attached\n ATTACHMENT=test.csv&SIZE=423789@@Heading 1.,Heading 2,Heading 3,Heading 4,Heading 5,Heading 6,Heading 7
60,Example,13,Example,Example,6.01,Example
64,Example,15,Example,Example,5.46,Example
21,Example,1,Example,Example,Example,Example
20,Example,4,Example Example,Example,Example

@J4ck 

Can you provide a picture of the desired output of the CSV file? Using the example you provided above.

Jason79
Frequent Visitor

Hi @J4ck 

After the HTML to text I have done the following to remove all the text upto and inc. 2nd @ plus the headers:

 

Jason79_0-1694587796152.png

Jason79_1-1694587852872.png

I then did splitbycomma and JSON steps in this video: How to parse a CSV file with Power Automate - YouTube

Jason79_4-1694588734043.png

 

 

After JSON step I added Parse JSON action, click Generate from sample and then paste in 

{
"Heading 1.": "",
"Heading 2": "",
"Heading 3": "",
"Heading 4": "",
"Heading 5": "",
"Heading 6": "",
"Heading 7": ""
}

 

I then have an excel file with a table using these headers. I then added a add row into a table action, selected that file and added the dynamic content from Parse JSON

 

Jason79_3-1694588603616.png

 

Jason79_2-1694588210056.png

 

My result below

Jason79_5-1694588934436.png

 

You could then add an action to send that file via email.

Hope this is of some help.

Jason79
Frequent Visitor

@J4ck 

Had another go but sending out a .csv file. Reiterate I'm a novice so there may be more smarter /efficient methods but I ended up receiving an email with a .csv attachment.

 

Re. my original post above. After and outside the apply to each add in below 

 

Jason79_0-1694599077917.png

 

Then add these steps

Jason79_1-1694599321393.png

Then add action to send email

 

Jason79_2-1694599450165.png

 

 

I utilised this: Instantly using Power Automate create CSV file and send email attachment - Global SharePoint Diary (...

 

I did receive email with email attachment which I haven't tried before 🙂

 

Jason79_3-1694599736023.png

 

J4ck
Frequent Visitor

Holy @Jason79 can't thank you enough for all this! Did not expect you to put this much work into it haha, really appreciated it and thanks for breaking it down as well I understand it all now!

 

It looks like "\n" is being put into the data when converting from HTML so just need to figure out how to remove this and it should all being working perfectly, again thanks so much! and thank you to everyone else who helped!!!

"

J4ck
Frequent Visitor

So after having done some research it looks like HTML to text automatically inputs these \n at random. Just in the example data provided it wasn't long enough to trigger this, if you were to use the below as the data source it will input these new lines and thus breaking the CSV formatting.

 

Warning: This email is not from a known sender.

Please find attached\n ATTACHMENT=test.csv&SIZE=423789@@Heading 1.,Heading 2,Heading 3,Heading 4,Heading 5,Heading 6,Heading 7
60,Example,13,Example, Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example,6.01,Example
64,Example,15,Example,Example,5.46,Example
21,Example,1,Example,Example,Example,Example
20,Example,4,Example Example,Example,Example

 

I have tried to replace \n with a space however I then get an error saying the CSVdata is null, so not sure if I'm doing something wrong and replacing everything?

 

J4ck_1-1694641726352.png

 

 

 

 

 

Hi @J4ck 

 

Thanks for the reply. 

My suggested flows takes the /n that splits the headers over 2 lines into account.

Replace all text up to and inc. 2nd @ removes all text to start of Heading 1. (not sure if there's supposed to be a '.')

Then CSV data action skip(outputs('Split_new_line'),2) skips the headers that are split over 2 lines because of the /n.

 

Output for csv data

[
  "60,Example,13,Example,Example,6.01,Example",
  "64,Example,15,Example,Example,5.46,Example",
  "21,Example,1,Example,Example,Example,Example",
  "20,Example,4,Example,Example,Example,Example"
]
 
If you need the headers on a single line you could use below in a new compose and then 
concat(first(outputs('Split_new_line')),outputs('Split_new_line')[1])
 
Raw out: "Heading 1.,Heading2,Heading 3,Heading 4,Heading 5,Heading 6,Heading 7"
 
Hope this helps
J4ck
Frequent Visitor

Hi @Jason79 

Thanks for all your help so far, the headings are perfect. It's when you add a certain amount of data it seems to add new lines, so for example if you were to input the below as the source data into the flow.

Warning: This email is not from a known sender.

Please find attached\n ATTACHMENT=test.csv&SIZE=423789@@Heading 1.,Heading 2,Heading 3,Heading 4,Heading 5,Heading 6,Heading 7
60,Example,13,Example, Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example Example,6.01,Example
64,Example,15,Example,Example,5.46,Example
21,Example,1,Example,Example,Example,Example
20,Example,4,Example Example,Example,Example


This outputs as 
"Warning: This email is not from a known sender. Please find attached\\n\nATTACHMENT=test.csv&SIZE=423789@@Heading 1.,Heading 2,Heading 3,Heading\n4,Heading 5,Heading 6,Heading 7 60,Example,13,Example, Example Example Example\nExample Example Example Example Example Example Example Example Example Example\nExample Example Example Example Example,6.01,Example\n64,Example,15,Example,Example,5.46,Example\n21,Example,1,Example,Example,Example,Example 20,Example,4,Example\nExample,Example,Example"

Which has serval new line calls within it, meaning the CSV is misaligned. I presume the best way to do this would be to replace the newline with just a space but I'm struggling to do so?

J4ck_0-1694718812113.png

 






Can you provide an example how you expect the data you pasted above to be displayed in a csv file?

Not every item is separated by a ',' so should each row have 7 data points and then start a new row? A cell will contain multiple items without the ','.

Header 1Header 2Header 3Header 4Header 5Header 6Header 7
       
       
       

 

replace(outputs(enter_output),decodeUriComponent('%0A'),' ') should replace \n

 

replace(outputs(enter_output),' ',',') should replace space with a comma

 

Hi @Jason79 

Here is the expected format from that data.

 

J4ck_0-1694803629998.png

It looks like when \n are being inputted this creates a new cell and breaks up my data when in fact I want it to be in the same cell, and thus everything after that is 1 column out because its been pushed out by the \n.

 

I have tried to implement the replace function as you mentioned but upon doing so I get the below error

"The 'from' property value in the 'table' action inputs is of type 'Null'. The value must be of type 'Array'."

J4ck_1-1694804063713.png

 

 

Hope that all makes sense, but if not feel free to let me know.

 

Again thanks a ton for all your time and help 🙂

 

Is this of any use?

Solved: html to text function adding random break lines is... - Power Platform Community (microsoft....

 

Haven't tested as a bit beyond my understanding.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages