javascript - 谷歌脚本的sendEmail(收件人,主题,正文)方法的html正文部分设计
问题描述
如何设计 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)
(此处的文档)在正文中生成 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);
要格式化您的表格,请参考此处。玩得开心。
推荐阅读
- asp.net-core - 实体框架核心 2.1。使用大量子对象更新对象的正确方法
- c++ - C++:矩阵的运算符重载
- excel - Nesting ParamArrays when declaring Excel VBA functions like SUMIFS?
- flutter - 检查约束并相应地返回正文
- android - 实时数据在更改片段时再次赋予旧值
- html - 如何将 Ionic 日期时间选择器定位到屏幕顶部?
- html - 缩放转换时列中的 CSS 元素位于上边框下方
- python - How can i remove double quotes in cmd title
- cassandra - Cassandra,如果集合包含值则删除
- android - 为小部件布局触发 Android 10 主题更新