0

我使用此代码发送带有附件的电子邮件,并且效果很好!

但是,我只能附加 .PDF 文件

我怎么能允许图像附件?

感谢任何可以提供帮助的人。

function sendEmails() {

  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('BD');
  const numRows = sh.getLastRow();
  const pdf = sh.getRange(numRows, 21).getValue();
  const fileid = pdf.slice(33, 66); //cut url id file drive
  const file = DriveApp.getFileById(fileid)

  var id_img_1 = '1flyOEuH1WWYCrQF91feRPIdvjsFh-YfX'
  var id_img_2 = '1S3p6maECfBiF3J0PnOVfZ64YRxHj00On'
  var picture1 = DriveApp.getFileById(id_img_1); 
  var picture2 = DriveApp.getFileById(id_img_2);
  var inlineImages = {};
      inlineImages[picture1.getId()] = picture1.getBlob();
      inlineImages[picture2.getId()] = picture2.getBlob();
  var my_id = numRows;
      my_id -= 1;

  sh.getRange(numRows, 1).setValue(my_id)    
  var email = sh.getRange(numRows, 2).getValue();

MailApp.sendEmail({

to: email,
subject: "test",
attachments: [file.getAs(MimeType.PDF)],
body: "Test message",
htmlBody:'<img src="cid:' + picture1.getId() + '" />' +
         "</pre><br/>\n"+
         "</pre><br/>\n"+
         '<img src="cid:' + picture2.getId() + '" />' +
         "</pre><br/>\n",
      inlineImages: inlineImages
      
      });

Tks

4

1 回答 1

0

虽然我不确定我是否能正确理解allow image attachment,但从您当前的脚本中,为了将图像附加为附件,以下修改如何?

从:

attachments: [file.getAs(MimeType.PDF)],

至:

attachments: [file.getAs(MimeType.PDF), picture1, picture2],
  • 如果您不想将图像用作内联图像,请删除您的htmlBodyand inlineImages
于 2021-11-30T00:24:39.067 回答