Google Apps脚本 - 使用html中的png自动发送电子邮件

时间:2015-11-27 02:31:29

标签: javascript php html email google-apps-script

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

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

档案名称:白色饮食 html: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)
}

1 个答案:

答案 0 :(得分:0)

MailApp documentation注意如何包含附件,但是如何附加图片有点模棱两可。

我建议使用参数.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]
});