我正在尝试在收件箱中测试 Gmail 的操作,特别是确认操作 ( https://developers.google.com/gmail/actions/reference/one-click-action#confirm_action )。我使用 Google 的 Apps Script 编写了一个脚本,将这个 JSON 嵌入到电子邮件中:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"action": {
"@type": "ConfirmAction",
"name": "Confirm Password Change",
"handler": {
"@type": "HttpActionHandler",
"url": "https://aerobic-forge-659.appspot.com?test=677"
}
}
}
</script>
然后发送给我自己。当我收到电子邮件时,“确认操作”按钮会正确显示,但是当我单击它时,会收到一条错误消息,内容为“无法向 gmail.com 发送请求”。我可以访问 servlet 页面的点击日志,根据日志,操作按钮根本没有访问该页面。
请求被发送到的 servlet 由 Google Apps Engine 托管,网址为:https ://aerobic-forge-659.appspot.com/ 。如果直接在浏览器中输入 url,它就可以正常工作。这是它的代码:
public class DemoServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("{ \"name\": \"World\" }");
resp.setStatus(HttpServletResponse.SC_OK);
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("{ \"name\": \"World\" }");
resp.setStatus(HttpServletResponse.SC_OK);
}
}
我已经在互联网上搜索试图找到解决这个问题的方法,但到目前为止还没有成功。我已确保为服务器使用安全 url,我正在使用 Google 的脚本发送电子邮件(所以我知道它们已经过正确身份验证),并且我只向我自己的电子邮件地址发送电子邮件(所以我还不需要向谷歌注册)。任何帮助/建议将不胜感激。