是否可以从Apps脚本发送动态电子邮件?

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

正在为我的公司构建一个内部请求批准系统,而我想开发的最佳方案是在Gmail中使用amp动态电子邮件(我们的公司依赖于G Suite服务)。

我进行了一些测试,并且在通过https://amp.gmail.dev/playground/发送时工作正常,但是当我尝试从GAS发送时,放大器的内容未显示(开发人员设置已启用,我自己的地址已列入白名单)。知道GAS有很多限制,我想知道是否甚至可以发送自动动态电子邮件。

function doGet(e) {          
  var body = HtmlService.createTemplateFromFile('body').evaluate().getContent()

  GmailApp.sendEmail(EMAIL_ADDRESS, new Date(), body, { htmlBody : body})          
}

HTML正文

<!DOCTYPE HTML>
    <html ⚡4email>
    <head>
      <meta charset="utf-8">
      <script async src="https://cdn.ampproject.org/v0.js"></script>
      <style amp4email-boilerplate>body{visibility:hidden}</style>
      <style amp-custom>
        h1 {
          margin: 1rem;
        }
      </style>
    </head>
    <body>
      <body>
  <amp-img src="https://placekitten.com/800/400"
           alt="Welcome"
           width="800"
           height="400">
  </amp-img>
</body>
    </body>
</html>
google-apps-script amp-html amp-email
1个回答
0
投票

用于电子邮件的AMP要求AMP是multipart/alternative MIME树中的单独部分,其中text/x-amp-htmlContent-Type。有关更多信息,请参见Structure and rendering of AMP emails

documentation for GmailApp.sendEmail具有以下说明:

发送带有可选参数的电子邮件。 电子邮件可以包含纯文本或HTML正文。电子邮件的大小(包括标题,但不包括附件)是受配额限制的。

因此,当前无法使用此API在电子邮件正文中包含所需的GmailApp.sendEmail部分。您现在拥有的代码将AMP代码放在text/x-amp-html部分中,电子邮件客户端会将这些代码视为常规HTML电子邮件,可能会导致剥离所需的标记和脚本。

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