谷歌应用程序脚本-自动电子邮件与png从html


Google Apps Script - automatic email with png from html

我创建了一个电子表格谷歌来收集电子邮件,并创建了一份脚本来自动发送带有文本+png图片的电子邮件。我没有成功。

你能帮我在自动电子邮件中添加附件吗?

文件名:White Diethtml:http://www.puresmile.com.au/wp-content/uploads/2015/10/Pure-Smile-White-Diet.png

这是我简单的(那个作品)脚本,但没有附上电子邮件中的图片。

function onFormSubmit(e) {
var timestamp = e.values[0];
var Firstname = e.values[1];
 var Lastname = e.values[2];
  var email = e.values[3];
 var subject = "Puresmile White Diet - recommendations 24 hours";
 var body = "Dear customer,'n'n Thank you for visiting Puresmile today.'n Please find the Puresmile White Diet attached. These after care recommendations will explain what to avoid and what's good for your white smile.'n'n To maintain your results for longer please:'n'n * avoid food or beverage (except water) for the next 2 hours after your treatment'n * follow the Puresmile White Diet for 24 hours after the treatment'n'n We hope you enjoyed your experience at our studio today!'n'n Best regards,'n Team Puresmile";
MailApp.sendEmail(email, subject, body)
}

MailApp文档注意到如何包含附件,但在如何附加图像方面有点模糊。

我建议使用参数.sendEmail(email, subject, body, {attachments: [BlobSource]})

例如:

// Set URL of image
var url = "http://www.puresmile.com.au/wp-content/uploads/2015/10/Pure-Smile-White-Diet.png";
// UrlFetchApp is the class to retrieve hosted content
// .fetch() retrieves the file
// .getBlob returns a "blob" object of the data
// .getAs("image/png") returns a usable PNG image
var image = UrlFetchApp.fetch(url).getBlob().getAs("image/png");
// Add the "options" to the sendEmail method, 
// where attachments is an array of Blobs
MailApp.sendEmail(email, subject, body, {
    attachments: [image]
});