我正试图将内联图像添加到电子邮件中,这是可行的,但它将图像作为附件添加。我是不是做错了什么?
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Data');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('Document.html');
var img = DriveApp.getFileById('1NgViZuezxzqugtGFp8vPXe234s00ZNwg').getBlob();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(emailAddress, 'Annual Review', html,{
htmlBody: html.evaluate().getContent(),
name: "Administrators",
from: aliases[0],
inlineImages: {image: img}
});
}
}
答案:
电子邮件的HTML部分需要有文件的img标记
代码示例:
function myFunction() {
const image = DriveApp.getFileById("<id-of-file>").getBlob().setName('name')
const html = '<body>' + 'Test <img src="cid:image">' + '</body>'
GmailApp.sendEmail('toAddress@domain.com', 'subject', 'message body', {
htmlBody: html,
inlineImages: {
'image': image
}
from: aliases[0]
})
}