2

我正在尝试设置Gmail 的电子邮件标记,但我无法在我的 Rails 应用程序中对其进行测试。

为了测试它,我将我的 ActionMailer SMTP 设置更改为如下:

# config/environments/development.rb
config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => 'gmail.com',
    :user_name => 'my_email@gmail.com',
    :password => '[REDACTED]',
    :authentication => 'plain',
    :enable_starttls_auto => true
}

My Mailer 设置默认值fromto地址,定义方法mail_action如下:

# app/mailers/test_mailer.rb
class TestMailer < ActionMailer::Base
  default from: "my_email@gmail.com"
  default to:   "my_email@gmail.com"

  def mail_action
    @data = confirm_action

    mail subject: "Mail action"
  end

  def confirm_action
    {
      "@context" => "http://schema.org",
      "@type" => "EmailMessage",
      "action" => {
        "@type" => "ConfirmAction",
        "name" => "Confirm registration",
        "handler" => {
          "@type" => "HttpActionHandler",
          "url" => "http://google.fr",
        },
      },
    }
  end
end

该方法根据Google 的文档confirm_action定义了我的操作的标记。

在该mail_action方法的视图中,我将标记添加到<head>

# app/views/test_mailer/mail_action.html.haml
!!! Strict
%html
  %head
    %title Mail Action

    = content_tag :script, type: 'application/ld+json' do
      = JSON.generate(@data).html_safe

  %body
    %h1 Mail Action
    %pre
      = JSON.generate(@data).html_safe

我只是从 Rails 控制台使用TestMailer.mail_action.deliver. 在我收到的电子邮件中,我可以清楚地看到标记,但是操作按钮不在这里:

Return-Path: <my_email@gmail.com>
Received: from gmail.com ([REDACTED IP ADDRESS])
        by mx.google.com with ESMTPSA id qg11sm20491658wic.17.2014.12.17.03.07.30
        for <my_email@gmail.com>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 17 Dec 2014 03:07:36 -0800 (PST)
Date: Wed, 17 Dec 2014 12:07:29 +0100
From: my_email@gmail.com
To: my_email@gmail.com
Message-ID: <549163f154ad5_3a153fea39063bec467c7@Pluto.mail>
Subject: Mail action
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html>
  <head>
    <title>Mail Action</title>
    <script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ConfirmAction","name":"Confirm registration","handler":{"@type":"HttpActionHandler","url":"http://google.fr"}}}
    </script>
  </head>
  <body>
    <h1>Mail Action</h1>
    <pre>{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ConfirmAction","name":"Confirm registration","handler":{"@type":"HttpActionHandler","url":"http://google.fr"}}}</pre>
  </body>
</html>

Gmail 收件箱

有谁知道我错过了什么/做错了什么?提前致谢 !

4

1 回答 1

0

要发送测试电子邮件,即使是给您自己,也需要使用 DKIM/SPF 对电子邮件进行签名,以防止出现以下问题中提到的欺骗:无法测试 GMail 自定义操作

您可以使用 Apps 脚本测试您的标记发送和电子邮件。当标记经过良好测试后,您就可以向 Google 注册。这是所需的信息https://developers.google.com/gmail/markup/registering-with-google#registration_guidelines

于 2014-12-17T17:05:42.760 回答