【问题标题】:Outlook shows HTML as TEXTOutlook 将 HTML 显示为 TEXT
【发布时间】:2011-10-31 16:46:51
【问题描述】:

我从我的 ruby​​ on rails 应用程序发送电子邮件。所有电子邮件客户端都可以正常显示我的电子邮件(gmail、bat、thunderbird 等),但 Outlook 不能:(

在前景中我看到了这个:

my message text

--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: multipart/related; charset=f-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: text/plain; charset=f-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

my email text message

--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: text/html; charset=f-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

my email html code (<h1>test</h1><table...)

--mimepart_4e514d8786c25_d59..fdab8042069c--

怎么了???

以防万一来自 Outlook 的标题:

Message-Id: <4e514d88.100fdf0a.403c.31a7@mx.xxx.ccc>
Subject: =?utf-8?Q?=D0=97=D0=B0=D0=BF=D1=80=D0=BE=D1=81_=D0=B4=D0=BB=D1=8F_=D0=BC=D0=B5=D0=BD=D0=B5=D0=B4=D0=B6=D0=B5=D1=80=D0=B0_=D0=BA=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8=D0=B8_?=
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4e514d8786c25_d59..fdab8042069c
User-Agent: Rails Application
X-Mailer: Rails Mailer
Return-Path: admin@xxx.ccc
X-Yandex-Forward: 8a20ef6ffc7eeb7ef7c8d000508718e0

来自 gmail 的同一封电子邮件,在文本和 html 模式下都显示良好:

Delive
Message-Id: <4e514d88.100fdf0a.403c.31a7@mx.xxx.com>
Subject: xxx
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4e514d8786c25_d59..fdab8042069c
User-Agent: Rails Application
X-Mailer: Rails Mailer
X-Yandex-Forward: 8a20ef6ffc7eeb7ef7c8d000508718e0


--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: multipart/alternative; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

email text 


--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: multipart/related; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline


--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

email text (plain text)

--mimepart_4e514d8786c25_d59..fdab8042069c
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline


email text(html)

--mimepart_4e514d8786c25_d59..fdab8042069c--

【问题讨论】:

  • 顶部的空多部分/相关替代方案有什么意义?我认为发送 multipart/* 类型的一部分而不为它定义内部分隔符并给它一个终止行是不合法的。
  • 另外,charset=f-8 不为 IANA 字符集注册表所知。

标签: html ruby-on-rails email outlook


【解决方案1】:

(1) 样本中的多部分结构是错误的;您需要实现这样的层次结构(使用适当的传输编码和其他细节):

Content-Type: multipart/alternative; boundary="LEVEL0"

--LEVEL0
Content-Type: text/plain; ...
email text...

--LEVEL0
Content-Type: multipart/related; boundary="LEVEL1"

--LEVEL1
Content-Type: text/html; ...
<html><body>...

--LEVEL1
Content-Type: image/jpeg; ...
...

--LEVEL1--

--LEVEL0--

(2) 某些 Outlook 版本在 Content-Disposition: inline header 显式设置为 "text/html" 部分时不会直接显示 HTML 消息。

【讨论】:

    【解决方案2】:

    您是如何构建这封邮件的?是否手动添加标题?

    我不知道 charset=f-8 来自哪里,但这是一个错误,它会呈现整个标题行包含Content-Type: text/html 部分无效。你很幸运,其他邮件客户并不觉得那里很严格。

    无效的标题行导致 Outlook 将该部分解释为纯文本,这是相当明智的。

    如果您没有手动添加这些标题,而 ActionMailer 反而变得厚颜无耻,请在您构建邮件的地方发布一些代码。可能值得发布另一个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      相关资源
      最近更新 更多