我正在尝试(但失败)使用 ActionMailer 配置 Ruby on Rails 应用程序以发送 AMP 电子邮件。寻找有关如何进一步调试的任何建议,因为现在我不知道还能做什么!
示例 AMP 模板在从AMP Gmail 游乐场发送时有效,但是当我从我们的 Rails 应用程序发送示例时,AMP 版本不会在 Gmail 中呈现。
在config/initializers/mime_types.rb
我补充说:
Mime::Type.register 'text/x-amp-html', :amp
AMP 标记位于名为app/views/reminder_mailer/foo_notification.amp.erb
. 对于测试,我的邮件方法如下所示:
def foo_notification
mail(to: 'foo@example.com', subject: 'Foo subject') do |format|
format.amp
format.text
format.html
end
end
我的 Rails 控制台的输出显示正确发送的邮件,Content-Type: multipart/alternative
后跟Content-Type: text/x-amp-html
. 完整的输出如下。
ReminderMailer#foo_notification: processed outbound mail in 19.9ms
Sent mail to foo@example.com (625.2ms)
Date: Thu, 06 Feb 2020 16:47:56 -0800
From: example <notifier@example.com>
Reply-To: example <notifier@example.com>
To: foo@example.com
Message-ID: <5e3cb3bc74b91_2cd13ff4e08417cc34068@Chris-MacBook-Pro.local.mail>
Subject: Test AMP email 62
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5e3cb3bc73df1_2cd13ff4e08417cc339b3";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5e3cb3bc73df1_2cd13ff4e08417cc339b3
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Plain text.
----==_mimepart_5e3cb3bc73df1_2cd13ff4e08417cc339b3
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<h1>Foo HTML content</h1>
<div>Hey yo this is the HTML.</div>
----==_mimepart_5e3cb3bc73df1_2cd13ff4e08417cc339b3
Content-Type: text/x-amp-html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!--=0D
Below is the mininum valid AMP4EMAIL document. Just type away=0D
here and the AMP Validator will re-check your document on the fly.=0D=
-->=0D
<!doctype html>=0D
<html =E2=9A=A14email>=0D
<head>=0D
<meta charset=3D"utf-8">=0D
<script async src=3D"https://cdn.ampproject.org/v0.js"></script>=0D
<style amp4email-boilerplate>body{visibility:hidden}</style>=0D
</head>=0D
<body>=0D
Hello, AMP4EMAIL world.=0D
</body>=0D
</html>=
----==_mimepart_5e3cb3bc73df1_2cd13ff4e08417cc339b3--
最后,我使用 Gmail 的 API 来检查完整的邮件内容。成功的 AMP 游乐场与来自 Rails 的失败 AMP 之间存在一些差异。例如,两者的值"name": "ARC-Authentication-Results"
显示不同。此外,AMP 游乐场电子邮件包含以下属性,这些属性不在失败的 AMP 电子邮件中:
{
"name": "X-Google-DKIM-Signature",
"value": ...
},
{
"name": "X-Gm-Message-State",
"value": ...
},
{
"name": "X-Google-Smtp-Source",
"value": ...
},
{
"name": "X-Received",
"value": ...
},
{
"name": "X-Google-Appengine-App-Id",
"value": "s~dynamic-mail-playground"
},
{
"name": "X-Google-Appengine-App-Id-Alias",
"value": "dynamic-mail-playground"
},