通过分配text / html内容类型字符串,以
HTML格式发送电子邮件(到Outlook)非常有用:
using (MailMessage message = new MailMessage()) { message.From = new MailAddress("--@---.com"); message.ReplyTo = new MailAddress("--@---.com"); message.To.Add(new MailAddress("---@---.com")); message.Subject = "This subject"; message.Body = "This content is in plain text"; message.IsBodyHtml = false; string bodyHtml = "<p>This is the HTML <strong>content</strong>.</p>"; using (AlternateView altView = AlternateView.CreateAlternateViewFromString(bodyHtml,new ContentType(MediaTypeNames.Text.Html))) { message.AlternateViews.Add(altView); SmtpClient smtp = new SmtpClient(smtpAddress); smtp.Send(message); } }
电子邮件在Outlook(2003)中被正确识别为HTML.
但如果我尝试富文本:
MediaTypeNames.RichText;
Outlook没有检测到这一点,它回退到纯文本.
如何以富文本格式发送电子邮件?