我创建了一个电子表格谷歌来收集电子邮件,我创建了一个脚本来自动发送带有文本 + png 图片的电子邮件。我没有成功。
你能帮我在自动邮件中添加附件吗?
文件名:白色饮食 网页格式: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
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]
});
关于javascript - Google Apps 脚本 - 使用来自 html 的 png 自动发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33949505/