Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web browser control display plain text mail

I have a c# app which is supposed to display email. the email may be HTML or plain text but i am using web browser control in both cases. the problem is web browser control is ignoring all the escape characters of plain text and the mail appear as a single line.

the work around i am using is to replace escape character "\n" or "\r" to <br>. is there any other good way to do this.

thanks in advance.

like image 713
Deepak Avatar asked Nov 30 '25 01:11

Deepak


2 Answers

You can surround the text with <pre> and </pre> (stands for "preformatted") tag. See here: HTML pre Tag

like image 111
Simon Mourier Avatar answered Dec 02 '25 13:12

Simon Mourier


I think, the only way is the replacing "\r\n" for <br/>. Use the StringBuilder class for it.

var htmlText = new StringBuilder(text);
htmlText.Replace("\r\n", "\n")
        .Replace("\r", "\n")
        .Replace("\n", "<br/>");
webBrowser.DocumentText = htmlText.ToString();
like image 35
TcKs Avatar answered Dec 02 '25 13:12

TcKs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!