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

Is it possible to send dynamic emails from Apps Script?

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

我做了一些测试,通过 https://amp.gmail.dev/playground/ 发送时工作正常,当我尝试从 GAS 发送时,放大器内容没有显示(开发者设置已经启用,我自己的地址是 white-listed).知道 GAS 有一些限制,我想知道是否有可能发送自动动态电子邮件。

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

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

htmlbody

<!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>

用于电子邮件的 AMP 要求 AMP 是 multipart/alternative MIME 树中的一个单独部分,text/x-amp-html 作为 Content-Type。有关详细信息,请参阅 Structure and rendering of AMP emails

documentation for GmailApp.sendEmail的解释如下:

Sends an email message with optional arguments. The email can contain plain text or an HTML body. The size of the email (including headers, but excluding attachments) is quota limited.

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