Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 发送html电子邮件和纯文本作为备选方案_C#_Email_System.net.mail - Fatal编程技术网

C# 发送html电子邮件和纯文本作为备选方案

C# 发送html电子邮件和纯文本作为备选方案,c#,email,system.net.mail,C#,Email,System.net.mail,我还遗漏了其他邮件属性吗?答案写在这篇文章中: 尝试切换消息部分的顺序,将HTML部分放在纯文本部分之后。它可能会工作:) 注意:我现在记不起我在哪里读过这篇文章(或者我是否确实读过),但切换的原因可能会有所帮助,因为我认为信息的首选部分可能是最后一部分 更新:我发现了一个地方,上面说多部分MIME消息中的部分应该按优先顺序递增——在第7.2.3节中,从第三段到最后一段开始 在添加text/html之后,gmail显示html内容。尽管Microsoft Exchange显示了邮件的html版本

我还遗漏了其他邮件属性吗?

答案写在这篇文章中:

尝试切换消息部分的顺序,将HTML部分放在纯文本部分之后。它可能会工作:)

注意:我现在记不起我在哪里读过这篇文章(或者我是否确实读过),但切换的原因可能会有所帮助,因为我认为信息的首选部分可能是最后一部分

更新:我发现了一个地方,上面说多部分MIME消息中的部分应该按优先顺序递增——在第7.2.3节中,从第三段到最后一段开始

在添加
text/html
之后,gmail显示html内容。尽管Microsoft Exchange显示了邮件的html版本,但它并不介意添加版本的顺序

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

PGgxPlZPREE8L2gxPg==

使用
AlternateViews
时,
Body
应为
text/plain
AlternateViews
以提供不同的内容类型。从文档()中:

要向MailMessage对象添加备用视图,请为该视图创建附件,然后将其添加到AlternateViews返回的集合中。使用Body属性指定文本版本,并使用AlternateViews集合指定具有其他MIME类型的视图


这是正确答案,谢谢
Subject: subject
Content-Type: multipart/alternative; boundary=--boundary_0_989afdbb-5fe4-4155-ba59-3d5ffdbb909e
Message-Id: <20161208131903.36280C956C@in-1.mail.xxx.net>

----boundary_0_989afdbb-5fe4-4155-ba59-3d5ffdbb909e
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

PGgxPlZPREE8L2gxPg==
----boundary_0_989afdbb-5fe4-4155-ba59-3d5ffdbb909e
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

dGVzdCBjb250ZW50
----boundary_0_989afdbb-5fe4-4155-ba59-3d5ffdbb909e--
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

PGgxPlZPREE8L2gxPg==
AlternateView plainView = AlternateView.CreateAlternateViewFromString("test content", Encoding.UTF8, "text/plain");
message.AlternateViews.Add(plainView);

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlContent, Encoding.UTF8, "text/html");
message.AlternateViews.Add(htmlView);