How to understand the value of mail.body

Hello, I am using gsuite activities to get incoming emails, now when I use mail.body method to get the “body” of the email, the string output looks like this:

reading through this, it actually contains the information that I need, any idea how to extract exactly what I need?

If you just want the text without formatting so as to make sense of the message, you can sequentially get rid of the HTML tags.
I have done this in one of my projects with the following approach:

Replace <br> <div> and <tr> (table row) tags with New Line to maintain message structure
emailBody = mailMessage.Body.Replace("<br>", Environment.NewLine)
emailBody = emailBody.Replace("<tr>", Environment.NewLine)
emailBody = emailBody.Replace("<div>", Environment.NewLine)

Remove header info including new line characters(works on multi-line)
emailBody = Regex.Replace(emailBody,"<head>(.|\n)*<\/head>",String.Empty)

Remove all and any remaining HTML tags (BR, DIV and TR are already taken care of)
emailBody = Regex.Replace(emailBody,"<.*?>",String.Empty)

Replace &nbsp; with blank space
emailBody = Regex.Replace(emailBody,"&nbsp;"," ")

Test output.
Console.WriteLine("===== Email As Plain Text =====" & emailBody)

2 Likes

Hi @Rasoul, since mail body is html so save the mail body content in a notepad file and save in the .html format
Thus u can able to read the mail body

Hope you got it

Regards
Nived N

Happy Automation

2 Likes

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