使用Google脚本发送带有pdf附件的邮件

时间:2019-07-30 08:57:59

标签: google-apps-script gmail email-attachments

我想发送带有pdf附件的电子邮件。在另一个文件中,我已经意识到该任务。但在当前情况下,它发送邮件但没有附件。我将当前代码与工作代码进行了比较,但是没有发现错误。

var pdf = DriveApp.getFileById(sourceSheet.getId()).getAs('application/pdf').getBytes();
  var mailAttach = {filename: (subject + "_" + today + ".pdf"), content:pdf, mimeType: 'application/pdf'};

  MailApp.sendEmail(recipient, subject, body, {
    attachements:[mailAttach],
    cc: recipientCC
  });

1 个答案:

答案 0 :(得分:0)

  var pdf = DriveApp.getFileById(sourceSheet.getId()).getAs('application/pdf').getBytes();
  var mailAttach = {filename: (subject + "_" + today + ".pdf"), content:pdf, mimeType: 'application/pdf'};

  MailApp.sendEmail(recipient, subject, body, {attachments:[mailAttach],cc: recipientCC});