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

查看:53
本文介绍了如何以富文本格式向 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);
  }
}

电子邮件在 Outlook (2003) 中被正确识别为 HTML.
但如果我尝试富文本:

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?

推荐答案

底线是,使用 System.Net.Mail 无法轻松做到这一点.

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

Outlook 中的富文本在 SMTP 世界(Exchange 外部)中作为 winmail.dat 文件发送.

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