如何在富文本格式发送电子邮件到Outlook? [英] How to send email in richtext format to Outlook?

查看:3029
本文介绍了如何在富文本格式发送电子邮件到Outlook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它的伟大工程通过像这样分配的text / html内容类型的字符串发送HTML格式的电子邮件(Outlook)中:

It works great to send emails (to Outlook) in HTML format by assigning the text/html content type string like so:

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);
  }
}



电子邮件被正确识别为HTML在Outlook(2003 )结果
但是,如果我尝试丰富的文本:

The email is correctly recognized as HTML in Outlook (2003).
But if I try rich text:

MediaTypeNames.RichText;



Outlook不会检测到这一点,回落到纯文本。结果
我如何在富文本格式发送电子邮件?

Outlook doesn't detect this, it falls back to plain text.
How do I send email in rich text format?

推荐答案

底线是,你不能做到这一点很容易使用系统。 Net.Mail。

The bottom line is, you can't do this easily using System.Net.Mail.

在Outlook中的富文本发送为SMTP世界Winmail.dat文件(Exchange之外)。

The rich text in Outlook is sent as a winmail.dat file in the SMTP world (outside of Exchange).

Winmail.dat文件是TNEF邮件。所以,你需要创建Winmail.dat文件(格式为TNEF规则)内的富文本。

The winmail.dat file is a TNEF message. So, you would need to create your richtext inside of the winmail.dat file (formatted to TNEF rules).

不过,这还不是全部。 Outlook使用RTF格式压缩的一个特殊版本,所以,你也需要向下压缩的RTF,它添加到Winmail.dat文件之前。

However, that's not all. Outlook uses a special version of compressed RTF, so, you would also need to compress your RTF down, before it's added to the winmail.dat file.

底线,这是很难做到的,除非客户端真的,真的需要这个功能,我会重新考虑它。

The bottom line, is this is difficult to do, and unless the client really, really needs this functionality, I would rethink it.

这是不是你可以用几行做在.NET代码。

This isn't something you can do with a few lines of code in .NET.

这篇关于如何在富文本格式发送电子邮件到Outlook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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