Save email .eml in csv

I want to read in all emails from my mail account, and save every email in its .eml format in a column of a csv. So every row should contain the .eml output in textual form.

How can I do this?

2 Likes

Hi @Niels1

Hope this article might be helpful to you.

cheers :smiley:

Happy learning :smiley:

2 Likes

Thank you for your response. However, this is not what Iā€™m searching for. I want to have something like this (imagine this is an excel file with 1 column called ā€œemailsā€):
emails
email1.eml as string
email2.eml as string
email3.eml as string
ā€¦

So I want to have the output of the ā€œSave Mail Messageā€ activity, but I want to save it as a string, and moreover want to save it for every email. The problem with this activity is that you only do this for 1 specific mail, so if you use a ā€œfor eachā€ activity" around this, it simply overwrites the file every time a new email is saved.

1 Like

You can count the total of your csv row and if you want to insert data just pass the count plus 1 so that you will not overwrite the previous value @Niels1

cheers :smiley:

Happy learning :smiley:

2 Likes

Ok so how can I do this concretely? Currently I do this:

  1. First, I use the ā€œGet IMAP Mail Messagesā€ activity to read in my mails. I save the output of this activity in a variable called ā€œemailsā€.
  2. I use a ā€œBuild DataTableā€ activity to create a data table in which I will write the .eml content of every email.
  3. I use a ā€œFor Eachā€ activity to loop over every email in the ā€œemailsā€ variable created in step 1.
  4. I use a ā€œAdd Data Rowā€ activity in this loop, because I want to add the .eml content of each mail as a new row in the DataTable variable. However, I have no idea on how to get the .eml content of a mail, convert it to a string and add it as a row in my data table.
1 Like

Hi @Niels1

I already share to you the article how you can save the email sa eml file and save anywhere you want and do your desire thing.

cheers :smiley:

Happy learning :smiley:

2 Likes

Yes I understand how I can save an email as an .eml file. But this activity only allows me to provide a file path. I donā€™t want to save it to a file, I want to save it as a row in a data table, and moreover, I want to do this for every email.

1 Like

Then after you save it to a row you want to save it to csv file or excel file am i correct ?
@Niels1

2 Likes

I figured it out. What I do is, for every email (which is a MailMessage object), I save it to a txt file using the ā€œSave Mail Messageā€ activity, and then use the ā€œRead Text Fileā€ activity to read the content of that file again and save it as a String variable. Then, I can add it to the DataTable using the ā€œAdd Data Rowā€ activity (with ArrayRow = {this String variable}).

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.