How to create a new line in the mailmessage.body section

I sent mail using SMTP (ASP.NET).

I wrote the text in only one line, but I want to be in the next line.

I used \n but it does not work.

+7
source share
2 answers

System.Environment.NewLine

If you format your email as HTML, you can add <br /> to it.

To format in HTML, use the IsBodyHtml property of the MailMessage class.

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml.aspx

+17
source

if IsBodyHtml == false, then https://social.msdn.microsoft.com/Forums/vstudio/en-US/82da38ac-ac20-4c9a-a2bd-8512d88fdd41/c-newline-in-email?forum=csharpgeneral suggests:

Use% 0D% 0A to split lines.

To simplify, use "\ r \ n", then call Uri.EscapeDataString for the body and subject before concatenation.

if IsBodyHtml == true, as suggested above, use <br /> You can use someText.Replace ("\ n", "<br />" ) to replace new lines (any remaining lines from r \ n lines will be ignored). Or use someText.Replace ("\ r \ n", "<br />" ). Replace ("\ n", "<br />" ) to fix both ends of the line without any leftover \ r if line-to-line mixed in the text.

0
source

All Articles