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

查看:42
本文介绍了如何在 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 
 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 的评论,如果 IsBodyHtml 设置为 true 那么标准换行符可能会被设计忽略,我知道您提到避免使用 HTML,但尝试使用 <br/> 代替,即使只是为了看看这是否解决"了问题 - 那么您可以根据您所知道的来排除:

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天全站免登陆