我的Rails 3应用程序以纯文本和HTML格式发送电子邮件。 我已经使用RoundCube和Squirrel Mail客户端在本地对其进行了测试,它们都显示带有图像,链接等的HTML版本。另一方面,GMail选择纯文本格式。 知道是什么原因造成的吗?

Received: by with SMTP id m2cs16081icy;
        Thu, 3 Mar 2011 17:01:48 -0800 (PST)
Received: by with SMTP id go10mr1544841qcb.195.1299200507499;
        Thu, 03 Mar 2011 17:01:47 -0800 (PST)
Return-Path: <>
Received: from ( [])
        by with ESMTP id j14si1690118qcu.136.2011.;
        Thu, 03 Mar 2011 17:01:46 -0800 (PST)
Received-SPF: neutral ( is neither permitted nor denied by best guess record for domain of client-ip=;
Authentication-Results:; spf=neutral ( is neither permitted nor denied by best guess record for domain of
Received: from localhost.localdomain (localhost [])
  by (Postfix) with ESMTP id F3C273A3EC
  for <>; Fri,  4 Mar 2011 01:01:45 +0000 (UTC)
Date: Fri, 04 Mar 2011 01:01:45 +0000
Message-ID: <4d7039f9e9d3e_3449482ab7831658@test.mail>
Subject: Your example account was activated.
Mime-Version: 1.0
Content-Type: multipart/alternative;
Content-Transfer-Encoding: 7bit

Date: Fri, 04 Mar 2011 01:01:45 +0000
Mime-Version: 1.0
Content-Type: text/html;
Content-Transfer-Encoding: 7bit
Content-ID: <4d7039f9e95ed_3449482ab7831519@test.mail>

    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <p><a href=""><img border="0" src="" alt="example logo" /></a></p>
    <p>Congratulations, Test!</p>
      Your <a style="text-decoration:none;color:#ef4923;" href="">example</a> account was activated.

Date: Fri, 04 Mar 2011 01:01:45 +0000
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
Content-ID: <4d7039f9e8b0e_3449482ab78314b7@test.mail>

Congratulations, Test!

Your account was activated.

Vincent asked 2020-08-02T19:30:09Z
92 votes

尝试切换消息各部分的顺序,将HTML部分放在纯文本部分之后。 它可能有效:)。


更新:我发现一个地方,它说多部分MIME消息中的部分应该按照优先级递增的顺序进行排列-在此处,在第7.2.3节(编辑:此处是最新版本;感谢@ALEXintlsos!),从第三个 最后一段。


7.2.3 The Multipart/alternative subtype
The multipart/alternative type is syntactically identical to multipart/mixed, 
but the semantics are different. In particular, each of the parts is an
"alternative" version of the same information. User agents should recognize
that the content of the various parts are interchangeable. The user agent
should either choose the "best" type based on the user's environment and
preferences, or offer the user the available alternatives. In general, choosing
the best type means displaying only the LAST part that can be displayed. This
may be used, for example, to send mail in a fancy text format in such a way
that it can easily be displayed anywhere:

From:  Nathaniel Borenstein <> 
To: Ned Freed <> 
Subject: Formatted text mail 
MIME-Version: 1.0 
Content-Type: multipart/alternative; boundary=boundary42 

Content-Type: text/plain; charset=us-ascii 

...plain text version of message goes here.... 

Content-Type: text/richtext 

.... richtext version of same message goes here ... 
Content-Type: text/x-whatever 

.... fanciest formatted version of same  message  goes  here 

In this example, users whose mail system understood the "text/x-whatever"
format would see only the fancy version, while other users would see only the
richtext or plain text version, depending on the capabilities of their system.

In general, user agents that compose multipart/alternative entities should
place the body parts in increasing order of preference, that is, with the
preferred format last. For fancy text, the sending user agent should put the
plainest format first and the richest format last. Receiving user agents should
pick and display the last format they are capable of displaying. In the case
where one of the alternatives is itself of type "multipart" and contains
unrecognized sub-parts, the user agent may choose either to show that 
alternative, an earlier alternative, or both.

NOTE: From an implementor's perspective, it might seem more sensible to reverse
this ordering, and have the plainest alternative last. However, placing the
plainest alternative first is the friendliest possible option when
multipart/alternative entities are viewed using a non-MIME- compliant mail
reader. While this approach does impose some burden on compliant mail readers,
interoperability with older mail readers was deemed to be more important in
this case.

It may be the case that some user agents, if they can recognize more than one
of the formats, will prefer to offer the user the choice of which format to
view. This makes sense, for example, if mail includes both a nicely-formatted
image version and an easily-edited text version. What is most critical, however,
is that the user not automatically be shown multiple versions of the same data.
Either the user should be shown the last recognized version or should 
explicitly be given the choice. 
Abbafei answered 2020-08-02T19:30:40Z
translate from