Hi, I am sending a string as the message through SMTP. But the final mail does not consider the tabs and newlines. What might be the problem Thanks in advance
I am guessing that you are sending the mail as HTML, in which cases spaces, tabs, and newlines will all get collapsed down to one space.
You'll need to convert tabs to
or similar, and replace newlines with <br>
tags (or wrap paragraphs with <p>
tags).
Alternately, you can send the mail as plain text, and those characters will be preserved:
var mail = new MailMessage();
mail.IsBodyHtml = false;
...
Try adding the following header:
Mime-Type: text/plain
This will make most email readers keep the whitespace intact, and most of the time enforce a fixed-width font.
If you're already using HTML mail, then encapsulating everything inside of a <pre></pre>
should do it. Or, if you're into CSS, you can do <div style="white-space: pre;">...</div>
.
Also, make sure that what you're sending through the server has \r\n
(0x0D, 0x0A) line endings and not just \n
(UNIX) or \r
(Mac).