正在Ruby on Rails中发布AMP电子邮件的问题

问题描述 投票:5回答:1

我正在尝试(但失败)使用ActionMailer配置Ruby on Rails应用程序以发送AMP电子邮件。正在寻找有关如何进一步调试的建议,我现在不知道该怎么办!

[从AMP Gmail playground发送时,示例AMP模板有效,但是当我从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的文件中。为了进行测试,我的mailer方法看起来像:

def foo_notification
  mail(to: '[email protected]', subject: 'Foo subject') do |format|
    format.amp
    format.text
    format.html
  end
end

我的Rails控制台的输出显示正确发送了Content-Type: multipart/alternativeContent-Type: text/x-amp-html的邮件。完整的输出如下。

ReminderMailer#foo_notification: processed outbound mail in 19.9ms

Sent mail to [email protected] (625.2ms)
Date: Thu, 06 Feb 2020 16:47:56 -0800
From: example <[email protected]>
Reply-To: example <[email protected]>
To: [email protected]
Message-ID: <[email protected]>
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"
 },
ruby-on-rails ruby actionmailer amp-html amp-email
1个回答
2
投票

AMP电子邮件仅在通过DKIM和SPF身份验证后才能工作。因此,您需要一个有效的域和一个在服务器上运行的应用程序。这些是工作必不可少的。这意味着您无法在本地主机中对其进行测试(至少对我不起作用)。

在ApplicationMailer中另一个值得注意的设置是这样设置:parts_order:

default from: "[email protected]",
        parts_order: [ 'text/plain', 'text/enriched', 'text/x-amp-html', 'text/html' ]

如果没有这样设置parts_order,那么某些电子邮件客户端(如Mail,Outlook将在输出中显示amp标签,默认情况下会显示最后一封电子邮件。

[我在Ruby on Rails here中创建了有关AMP电子邮件的博客文章。

© www.soinside.com 2019 - 2024. All rights reserved.