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

标签 javascript php html email google-apps-script

我创建了一个电子表格谷歌来收集电子邮件,我创建了一个脚本来自动发送带有文本 + 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/

相关文章:

php - 当鼠标悬停在图像上时如何在图像上显示缩放按钮

javascript - 用于模态弹出窗口的 SlideUp Jquery

javascript - React 在重新渲染父组件时如何重用子组件/保持子组件的状态?

php - 查看javascript生成的html页面的实际html源

php - 在 PHP 中检测无限数组递归?

javascript - 自定义 jquery Accordion 箭头

javascript - 如何在页脚中包含 jquery - 在页眉中使用 $(document).ready 时?

javascript - Nativescript Vue 带有 v-bind 的切换按钮

javascript - 如何创建 JSONP 回调?

php - 在php中包含文件