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:
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 with blank space emailBody = Regex.Replace(emailBody," "," ")
Test output. Console.WriteLine("===== Email As Plain Text =====" & emailBody)