[英]how to give new line in mailmessage.body section
I have sent mail using SMTP (ASP.NET).我已使用 SMTP (ASP.NET) 发送邮件。
I have written text in one line only, but I want to be in next line.我只在一行写了文字,但我想在下一行。
I used \\n
, but it's not working.我使用了
\\n
,但它不起作用。
System.Environment.NewLine系统.环境.NewLine
If you format your email as HTML you can add a <br />
to it.如果您将电子邮件格式化为 HTML,则可以向其中添加
<br />
。
To format as HTML use the IsBodyHtml property of the MailMessage class.要格式化为 HTML,请使用 MailMessage 类的 IsBodyHtml 属性。
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml.aspx http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml.aspx
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:如果 IsBodyHtml == false,则https://social.msdn.microsoft.com/Forums/vstudio/en-US/82da38ac-ac20-4c9a-a2bd-8512d88fdd41/c-newline-in-email?forum=csharpgeneral建议:
Use %0D%0A to separate lines.
使用 %0D%0A 分隔行。
To simplify, use “\\r\\n”, then call Uri.EscapeDataString for body and subject before concatenation.
为简化起见,使用“\\r\\n”,然后在连接前为主体和主题调用 Uri.EscapeDataString。
if IsBodyHtml == true, as suggested above, use <br />
You can use someText.Replace("\\n", "<br />"
) to replace newlines (any remaining \\r from \\r\\n line endings will be ignored).如果 IsBodyHtml == true,如上所述,请使用
<br />
您可以使用 someText.Replace("\\n", "<br />"
) 来替换换行符(\\r\\n 行尾中的任何剩余 \\r 将被忽略)。 Or use someText.Replace("\\r\\n", "<br />"
).Replace("\\n", "<br />"
) to fix both line endings without any \\r remainders, if line-endings are intermixed in text.或者使用 someText.Replace("\\r\\n",
"<br />"
).Replace("\\n", "<br />"
) 来修复两个行尾而没有任何 \\r 余数,如果行尾在文本中混杂。
I solved the problem this way :我这样解决了这个问题:
Replace \\n by \\t\\n用 \\t\\n 替换 \\n
The tab will not be shown, but the newline will work.该选项卡将不会显示,但换行符将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.