Mail Message blank

I am not able to get the body message in IMAP as I have used System.Text.RegularExpressions.Regex.Replace(Mail.Body, “<[^>] “, “”).
My output gets blanks.
I have seen the solution as system.Text.RegularExpressions.Regex.Replace(mail.Headers(“HTMLBody”),”(<.?>)|({.*})”,“”), But this one get all the signature strings too, I would like to have only a body mail.
Your help in this matter will be great thankful.

Hi @James90

What exactly are you trying to match using the RegEx <[^>] ?

I am not matching here, I am trying to replace the

, , Envirnoment.Newline in my mail body message. And just get the message only.

If I understood well, you’re trying to replace a new line with an empty string, so I think it’s going to be easier if you use this :

Mail.Body.Replace(vbCr, "").Replace(vbLf, "")

Its not only about replace but I am not getting any mail message, even in mail.body.


I find error in your code sir.

can you screenshot the error details, what does it say?

It says that Compliler error(s) encountered processing expression “mail.Body.Replace.(vbCr, “”).Replace(vblf, “”)”.
Identifier expected.
Thank you

A dot has been somehow added between the first Replace and (vbCr, “”) just delete it and the error will fade away.

Now about the Mail Body do you have a blank result if you place it in a message box without any added Replace or any other method?

Hi @James90,

If your mail body is in html format, you can use mail.Headers("PlainText") to extract the text contents. If you want to use other keys, please refer this.
Warm regards,
Nimin


I got the message like this.

By using this code “System.Text.RegularExpressions.Regex.Replace(mail.Headers(“HTMLBody”),”(<.?>)|({.})“,”“)” I can retrive the message


I would like to have the message From “Name” to “test”.
Your help in this matter will really a greate thankful.
Best regards,
James

Hi @James90,

Instead of using the regular expression, just use mail.Headers("PlainText") and kindly update the output.

Warm regards,
Nimin

Hi @James90,

Please try the regex System.Text.RegularExpressions.Regex.Replace(mail.Headers(“HTMLBody”),"(<.*?>)|({.*})|(.*[}\)--{;]\s?\r\n)|(\r?\n@.*)|(.*[}{;]$)",String.Empty).Trim
If anything else needs to remove from the result, please let me know.

Warm regards,
Nimin