Reading Email Body and writing in excel

Hi All,
I want to read the body of my email based on a particular subject and copy the subject and the body of the mail in an excel. Can anyone help me with that?

Hi @Rahul_Rama,

What are you using for email i.e Gmail/Outlook/Exchange?
So just save all the messages in a list of mail messages and follow these steps:

  1. Iterate in mails using For Each loop.
  2. Use this type of condition in If block under For Each loop to select the particular mail from particular subject (item.Subject.Contains(“ABC Text”)). it will return the boolean.
  3. Based on the above boolean and save the body in variable using Assign activity to save the body you can use this syntax -> item.Body.ToString
  4. After all these steps use can use write Range activity to save all the information in Excel.
    If you want to write any particular data table from the mail body then go through this thread. it will help you.

Best!!
Anmol

2 Likes

@anmolk171 I am using outlook with my gmail account configured in it . I will implement what you told and let you know if it works :slight_smile:

1 Like

Sure buddy @Rahul_Rama. You can also take a look at the sample work flow attached in the above thread.

1 Like

@anmolk171 when I am storing the body of the email in a variable called body whose data type is Generic and displaying the value in a message box I get blank message boxes instead of the body. Can you please assist ?Main.xaml (7.5 KB) . I have attached my xaml file as well

@Rahul_Rama - Try using item.Body.ToString and you have checked the option only unread message in Get Outlook mail message activity.

Best!!
Anmol

@anmolk171 I tried what you suggested by still getting blank message box. I want to retrieve below email . As per my xaml file i should get two message box right? Main.xaml (6.4 KB)
image

Can Anybody help me with above problem?

@Rahul_Rama

What error are you getting ?

@lakshman I am getting blank message boxes whem i am displaying the body of the email

@Rahul_Rama

Because you kept the message box after the For Each loop and keep it inside Then and try once.

And also it seems like that mail came in 2013 and you are reading top 30 mails from mail box and is that mail fall under first 30 list or not ?

@lakshman
For 1st point I will implement and let you know if it works

For 2nd point I purposefully arranged my message box by subject and did oldest on top so yes 2013 mail come under first 30 .

Just for my understanding will the above setting be understood by uipath ?

1 Like

@Rahul_Rama

I don’t think so it will work.

Keep new mails as first and keep that mail in first 30 mails and then give it a try once. And also try oldest mails as first and give it a try once. Both cases check and let me know.

1 Like

This is how it looks in an email body when copied and pasted from excel. I need to grab it from an email body then transfer it to excel and use excel application scope.

Is that true that when registering some email boxes, you need to show your postal details including zip code https://worldpostalcode.com/united-states/florida/orlando? I have always thought it is linked to your IP address and that’s it. As I am very far from all these rules, can someone clarify it for me? Actually, I do not want to show any personal information for my email box. Can I still create it without showing postal details?

Hello @lakshman, for me also i am getting blank message while i am trying to retrive body from the email the message box shows blank message.

Whether you register with Postal Code or not, you have to register with email boxes, your IP is always linked with your account, Provide your post code like this: https://countrywisecodes.com/france/Occitanie/zip-codes
Is it mandatory or optional, we can have account without Zip or Postal code?

Hi Anmol,

How can we directly store the output of item.Body.ToString to an excel file without adding a data table in this task ?
I have tried this
body =item.Body.Tostring

we can show the output using Message Box activity simply , but if we need to write the output to an excel we need to use Data Table before Write Range activity Right ?