如何在C#发送多部分MIME消息? [英] How to send multi-part MIME messages in c#?

查看:188
本文介绍了如何在C#发送多部分MIME消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要与HTML组件加上人,他们的电子邮件客户端不能处理HTML纯文本组件发送多部分MIME邮件。在 System.Net.Mail.MailMessage 类似乎并不支持这一点。你怎么办呢?

I want to send multi-part MIME messages with an HTML component plus a plain text component for people whose email clients can't handle HTML. The System.Net.Mail.MailMessage class doesn't appear to support this. How do you do it?

推荐答案

D'哦,这是非常简单的......但我会离开这里的答案任何人谁像我一样,来得如此看好的答案谷歌搜索...前:)

D'oh, this is really simple... but I'll leave the answer here for anyone who, like me, came looking on SO for the answer before Googling... :)

感谢的这篇文章

使用 AlternateViews ,像这样:

//create the mail message
var mail = new MailMessage();

//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");

//set the content
mail.Subject = "This is an email";

//first we create the Plain Text part
var plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");
//then we create the Html part
var htmlView = AlternateView.CreateAlternateViewFromString("<b>this is bold text, and viewable by those mail clients that support html</b>", null, "text/html");
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);

//send the message
var smtp = new SmtpClient("127.0.0.1"); //specify the mail server address
smtp.Send(mail);

这篇关于如何在C#发送多部分MIME消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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