如何在C#System.Net.Mail.MailMessage中创建多行体 [英] How to create a multi line body in C# System.Net.Mail.MailMessage

查看:115
本文介绍了如何在C#System.Net.Mail.MailMessage中创建多行体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果将body属性创建为

If create the body property as

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

message.Body ="First Line \n second line";

我也尝试过

message.Body ="First Line" + system.environment + "second line";

当我收到消息(使用outlook)时,这两个都被忽略。

Both of these were ignored when I received the message (using outlook).

关于如何获取多行的任何想法?我试图避免html编码,以便电子邮件将播放更好的垃圾邮件过滤器。

Any ideas on how to get mutliple lines? I am trying to avoid html encoding so that the email will play nicer with spam filters.

谢谢

推荐答案

根据drris的评论, code> IsBodyHtml 设置为true,那么标准的换行符可能会被设计忽略,我知道你提到避免HTML,但尝试使用< br /> / code>,即使只是看看这个解决的问题 - 那么你可以排除你所知道的:

As per the comment by drris, if IsBodyHtml is set to true then a standard newline could potentially be ignored by design, I know you mention avoiding HTML but try using <br /> instead, even if just to see if this 'solves' the problem - then you can rule out by what you know:

var message = new System.Net.Mail.MailMessage();
message.Body = "First Line <br /> second line";

您也可以尝试将 IsBodyHtml false ,并确定在这种情况下换行是否正常工作,但是除非您明确将其设置为 true ,否则我很确定它仍然默认为 false

You may also just try setting IsBodyHtml to false and determining if newlines work in that instance, although, unless you set it to true explicitly I'm pretty sure it defaults to false anyway.

另外作为附注,避免电子邮件中的HTML不一定有任何帮助通过垃圾邮件过滤器获取消息,AFAIK - 如果有的话,您做的最多的是确保跨邮件客户端在布局方面的兼容性。要通过垃圾邮件过滤器玩得很好,应该考虑其他一些问题;甚至与邮件的主题和内容一样多,邮件是从哪里发送的,以及他们在哪里和他们等等。电子邮件根本不会被歧视,因为标有HTML。

Also as a side note, avoiding HTML in emails is not necessarily any aid in getting the message through spam filters, AFAIK - if anything, the most you do by this is ensure cross-mail-client compatibility in terms of layout. To 'play nice' with spam filters, a number of other things ought to be taken into account; even so much as the subject and content of the mail, who the mail is sent from and where and do they match et cetera. An email simply won't be discriminated against because it is marked up with HTML.

这篇关于如何在C#System.Net.Mail.MailMessage中创建多行体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆