"&" being read as "&" while reading email

Hi,

I am reading email using imap

Mail.headers(“htmlbody”).toString

When i read email body through above code, “&” gets converted to “&”

Any resolution?

1 Like

Hi @garimavarshney9,

Are you purposely reading html body.

If not please try Mail.body so that it returns string which can be used.

Thanks :slight_smile:

4 Likes

The ampersand sign & is encoded in html as &amp since you are extracting the actual html and turning it into a string, if you see & the literal html string being returned is correct at &amp

Here is my favorite website for all things html that explains it a bit: HTML Entities

1 Like

I need only the string from email body. Bur using imap, i am only able get html body since mail.body returns empty string. Any other way to get text from email without html

1 Like

Hey @garimavarshney9,

Try Mail.headers(“PlainText”)

This will give you the string from the email body.

Thanks :slight_smile:

I cannot see plain Text listed in Headers for my mailmessage.

Is getting the body using mail.headers(“HTMLBody”) and then replacing the characters and HTML using regex and string manipulation the only way left?