简体   繁体   English

Google Apps脚本在Google驱动器中发送带有附件jpg文件的电子邮件

[英]Google apps script sends email with attached jpg file in google drive

 function pic() { var userEmail = "sikrarin.pooh@gmail.com"; var firstName ="test"; var Subject = "test" var file = DriveApp.getFileById('0B1j-ntZn6vurRkZVVEpxWmRGSlU'); MailApp.sendEmail({ to: userEmail, subject: Subject, attachment:[file,blob] }) } 

I am tryinh to send an email with a jpg file from google drive, but it doesn't work. 我正在tryinh从Google云端硬盘发送带有jpg文件的电子邮件,但是它不起作用。 Help me please. 请帮帮我。

From this Google documentation , attachments parameter should be BlobSource[] type and it's an array of files to send with the email. 在此Google文档中attachments参数应为BlobSource[]类型,并且是与电子邮件一起发送的文件数组。

Example from the documentation: 文档中的示例:

 // Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
 var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
 var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
 MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', {
     name: 'Automatic Emailer Script',
     attachments: [file.getAs(MimeType.PDF), blob]
 });

Check if this code will work for you: 检查此代码是否对您有用:

function pic()
{

var userEmail = "sikrarin.pooh@gmail.com";
var firstName ="test";
var Subject = "test"
var file = DriveApp.getFileById('0B1j-ntZn6vurRkZVVEpxWmRGSlU');

MailApp.sendEmail(userEmail, Subject{
attachment:[file,blob]    
});

}

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发送带有附件的电子邮件,并使用Google Apps脚本保存在Google云端硬盘中 - Send an email with attachment and save in Google Drive using Google Apps Script 使用Google Apps脚本将Google驱动器中的pdf附加到电子邮件 - Attach a pdf from google drive to an email using google apps script 使用 Google Apps 脚本将文件上传到我的 google 驱动器(在 GOOGLE 中没有表格) - Upload file to my google drive with Google Apps Script (NO FORM IN GOOGLE) Google Apps脚本:用于在Google驱动器中导入xlsx文件的脚本 - Google apps script : script to import xlsx file in google drive Google Apps Script 如何链接到 Google Drive 上的 JS 或 CSS 文件 - Google Apps Script How to link to JS or CSS file on Google Drive 如何使用 Google Apps Script 将 JSON 文件保存到 Google Drive? - How to Save a JSON file to Google Drive using Google Apps Script? 从 Google Apps 脚本将 mp3 文件上传到 Google Drive - Uploading mp3 file to Google Drive from Google Apps Script google 应用程序脚本:file.setOwner() 未在 Google Drive 中转移所有权 - google apps script: file.setOwner() Not Transferring Ownership in Google Drive 使用 Google Apps 脚本将 JSON 文件写入和检索到 Google 云端硬盘 - Write and retrieve JSON file to Google Drive using Google Apps Script Google Apps脚本-从Google云端硬盘添加文件 - Google Apps Script - Add file from Google Drive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM