我正在尝试设置Gmail的电子邮件标记,但无法在Rails应用程序中对其进行测试。
为了对其进行测试,我将ActionMailer SMTP设置更改如下:
# config/environments/development.rb
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => '[email protected]',
:password => '[REDACTED]',
:authentication => 'plain',
:enable_starttls_auto => true
}
我的邮件程序设置默认值from
和to
地址,并定义以下方法mail_action
:
# app/mailers/test_mailer.rb
class TestMailer < ActionMailer::Base
default from: "[email protected]"
default to: "[email protected]"
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
该方法confirm_action
根据Google的文档为我的操作定义了标记。
在该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: <[email protected]>
Received: from gmail.com ([REDACTED IP ADDRESS])
by mx.google.com with ESMTPSA id qg11sm20491658wic.17.2014.12.17.03.07.30
for <[email protected]>
(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: [email protected]
To: [email protected]
Message-ID: <[email protected]>
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>
有谁知道我在想什么/做错了什么?提前致谢 !
要发送测试电子邮件,甚至发送给自己,也需要使用DKIM / SPF进行签名,以防止出现此问题中提到的欺骗:无法测试GMail自定义操作
您可以使用Apps Script测试标记发送和发送给自己的电子邮件。经过正确测试的标记之后,您就可以向Google注册。这是所需的信息https://developers.google.com/gmail/markup/registering-with-google#registration_guidelines
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句