我使用此代码发送带有附件的电子邮件,并且效果很好!
但是,我只能附加 .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