可以从Apps Script发送动态电子邮件吗?

huangapple go评论61阅读模式
英文:

Is it possible to send dynamic emails from Apps Script?

问题

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

我进行了一些测试,通过https://amp.gmail.dev/playground/发送工作正常,但当我尝试从GAS发送时,amp内容不显示(已启用开发者设置,我的地址已加入白名单)。知道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>
英文:

'm building an internal request-approval system for my company, and the best scenario I'd like to develop is using the amp dynamic emails in Gmail (our company relies on G Suite services).

I made some few tests, and while sending through https://amp.gmail.dev/playground/ is working fine, when I try to send from GAS the amp content is not showing (Developer settings already enabled, my own address is white-listed). Knowing that GAS has some various limitations, I'd like to know if it's even possible to send automated dynamic emails.

function doGet(e) {          
  var body = HtmlService.createTemplateFromFile(&#39;body&#39;).evaluate().getContent()
          
  GmailApp.sendEmail(EMAIL_ADDRESS, new Date(), body, { htmlBody : body})          
}

the html body

&lt;!DOCTYPE HTML&gt;
    &lt;html ⚡4email&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;script async src=&quot;https://cdn.ampproject.org/v0.js&quot;&gt;&lt;/script&gt;
      &lt;style amp4email-boilerplate&gt;body{visibility:hidden}&lt;/style&gt;
      &lt;style amp-custom&gt;
        h1 {
          margin: 1rem;
        }
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;body&gt;
  &lt;amp-img src=&quot;https://placekitten.com/800/400&quot;
           alt=&quot;Welcome&quot;
           width=&quot;800&quot;
           height=&quot;400&quot;&gt;
  &lt;/amp-img&gt;
&lt;/body&gt;
    &lt;/body&gt;
&lt;/html&gt;

答案1

得分: 2

AMP for Email要求AMP作为multipart/alternative MIME树中的一个单独部分,其Content-Typetext/x-amp-html。详细信息请参阅AMP电子邮件的结构和渲染

关于GmailApp.sendEmail文档解释如下:

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

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

英文:

AMP for Email requires the AMP to be a separate part in a multipart/alternative MIME tree with text/x-amp-html as the Content-Type. See Structure and rendering of AMP emails for more information.

The documentation for GmailApp.sendEmail has the following explanation:

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

Therefore, it's not currently possible to include the required text/x-amp-html part in the email body using this API. The code you have now is putting the AMP code inside the text/html part which email clients will treat as regular HTML email, likely resulting in stripping the required markup and scripts.

huangapple
  • 本文由 发表于 2020年1月6日 21:03:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612629.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定