英文:
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('body').evaluate().getContent()
GmailApp.sendEmail(EMAIL_ADDRESS, new Date(), body, { htmlBody : body})
}
the html body
<!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>
答案1
得分: 2
AMP for Email要求AMP作为multipart/alternative
MIME树中的一个单独部分,其Content-Type
为text/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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论