我正在尝试设置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 设置默认值from
和to
地址,定义方法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>
有谁知道我错过了什么/做错了什么?提前致谢 !