Google apps script 如何使用MailApp附加图像?

Google apps script 如何使用MailApp附加图像?,google-apps-script,google-drive-api,Google Apps Script,Google Drive Api,我正在尝试使用google MailApp Api发送电子邮件,以下是我目前所掌握的信息: function myEmailer(mySubject,imgKey) { var toEmail ='example@example.com'; MailApp.sendEmail({ to: toEmail, subject: mySubject, attachments:DriveApp.getFileById(imgKey)//this should atta

我正在尝试使用google MailApp Api发送电子邮件,以下是我目前所掌握的信息:

function myEmailer(mySubject,imgKey) {

  var toEmail ='example@example.com';

  MailApp.sendEmail({
    to: toEmail,
    subject: mySubject,
    attachments:DriveApp.getFileById(imgKey)//this should attach an image from my google drive
   });

}
我收到的电子邮件很好,但我没有附件


关于我这里遗漏的内容有什么想法吗?

你确定你的ID是正确的吗

请尝试以下测试:

function test(){  
  var mySubject = 'test';
  var imgKey = '0B3qSFd3iikE3Z1ZWcmlWQTFvWDQ'
  myEmailer(mySubject,imgKey) 
}

function myEmailer(mySubject,imgKey) {
  var toEmail = Session.getActiveUser().getEmail();
  MailApp.sendEmail({
    to: toEmail,
    subject: mySubject,
    attachments:DriveApp.getFileById(imgKey).getBlob()//this should attach an image from my google drive
  });
}

谢谢我使用了错误的键来调出图像。原来我是想从文件夹中取出密钥,而不是图像本身。