gpt4 book ai didi

javascript - google 脚本的 sendEmail(recipient, subject, body) 方法的 html 正文部分设计

转载 作者:行者123 更新时间:2023-12-02 23:13:44 24 4
gpt4 key购买 nike

如何设计 Google App 脚本的 sendEmail(recipient, subject, body) 正文部分以以表格格式发送电子邮件?下面是我的代码,我想用 Html 设计正文部分。请帮忙。

function sendEmails() {

var app = SpreadsheetApp;
var targetSheet = app.getActiveSpreadsheet().getSheetByName("Main_Template");

var i,j; var k=4;
for(i=2; i<=3; i++){
var infoData = [];
for(j=2; j<=5; j++){

var cellValues = targetSheet.getRange(i, j).getValue();
infoData.push(cellValues);
}

var emailSheet = app.getActiveSpreadsheet().getSheetByName("Emails");
var currentEmail = app.getActiveSheet().activate().getRange(i, 1).getValue();
var subject = app.getActiveSheet().activate().getRange(i, 2).getValue();

//var emailQuotaRemaining = MailApp.getRemainingDailyQuota();
//Logger.log("Remaining email quota: " + emailQuotaRemaining);

MailApp.sendEmail(currentEmail, subject,
"\n\n(FY 2019-20) % of NRM Expenditure: "+ infoData[0]
+ "\n\n(FY 2019-20) % of Timely MGNREGA wage payment: " + infoData[1]
+ "\n\n(FY 2017-18 & Earlier) % of Work Completion: " + infoData[2]
+ "\n\n(FY 2018-19) No. of rejected transactions pending regeneration: " + infoData[3]);
}
}

最佳答案

您需要使用 sendEmail(recipient, subject, body, options) ( docs here ) 在正文中生成 HTML 表格。

在您的代码中,替换此

   MailApp.sendEmail(currentEmail, subject,
"\n\n(FY 2019-20) % of NRM Expenditure: "+ infoData[0]
+ "\n\n(FY 2019-20) % of Timely MGNREGA wage payment: " + infoData[1]
+ "\n\n(FY 2017-18 & Earlier) % of Work Completion: " + infoData[2]
+ "\n\n(FY 2018-19) No. of rejected transactions pending regeneration: " + infoData[3]);
}

有了这个

var body = "<table border = '1'>" +
"<tr> <td> (FY 2019-20) % of NRM Expenditure: </td><td>" + infoData[0] + "</td></tr>" +
"<tr> <td> (FY 2019-20) % of Timely MGNREGA wage payment: </td><td>" + infoData[1] + "</td></tr>" +
"<tr> <td> (FY 2017-18 & Earlier) % of Work Completion: </td><td>" + infoData[2] + "</td></tr>" +
"<tr> <td> (FY 2018-19) No. of rejected transactions pending regeneration: </td><td>" + infoData[3] + "</td></tr>" +
"</table>";

var options = {
htmlBody : body
}

MailApp.sendEmail(currentEmail, subject, "", options);

要格式化表格,ref here 。玩得开心。

关于javascript - google 脚本的 sendEmail(recipient, subject, body) 方法的 html 正文部分设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57239191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com