在脚本中的文本之后插入图像

时间:2018-11-18 12:16:18

标签: google-apps-script google-sheets

我对应用脚本非常陌生,并设法将以下脚本作为独立的邮件合并在一起;

function sendEmail() {

SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Emails").activate();

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();

var templateText = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email 
Template").getRange(1, 1).getValue();

var quotaLeft = MailApp.getRemainingDailyQuota();

if((lr-1) > quotaLeft){
Browser.msgBox("You have " + quotaLeft + " email quota left for the 
day and you are trying to send " + (lr-1) + " emails. 0 emails were 
sent"); 
} else {

for (var i = 2;i<=lr;i++){

var currentEmail = ss.getRange(i, 4).getValue();
var SiteURL = ss.getRange(i, 5).getValue();
var FirstName = ss.getRange(i, 2).getValue();

var messageBody = templateText.replace("{{First Name}}",FirstName);
var subjectline = "Looking to partner with " + SiteURL;


MailApp.sendEmail(currentEmail, subjectline, messageBody);

} // close for loop

}  // close else statement

}

过去的几天我一直在搜索,试图在邮件正文之后插入来自网络的图像,但这似乎超出了我的理解水平。

一些提示或帮助,将不胜感激。 J

1 个答案:

答案 0 :(得分:0)

如果您想在电子邮件中发送嵌入式图像,则需要向options对象提供htmlBody。这是一个片段。

var messageBody = templateText.replace("{{First Name}}",FirstName);
var imageUrl = "https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png"

var htmlBody = messageBody + "<br><img src='" + imageUrl + "'>";

MailApp.sendEmail(currentEmail, subjectline, messageBody, {htmlBody: htmlBody});