我是一名新编码员,我的任务是:发送带有google-app-scripts格式的电子邮件,但是根据接收电子邮件的人的不同内容(例如姓名,截止日期,日期,一些小事。) 因此,我尝试编写此任务的代码,同时使用Java脚本和html,但现在我停留在这里。
如果我使用此方法:“ MailApp.sendEmail(emailAddress,收件人,主题,消息)” =>内容将根据我设置的某些变量灵活更改。但是此方法无法格式化电子邮件中的内容。
因此,我更改为另一种方法:“ MailApp.sendEmail(emailAddress,主题,'',options)”。在这种方法中,我们可以使用html代码来格式化电子邮件中的内容,但不能使用var灵活地更改内容。
所以任何人都深刻理解了如何在html标签中使用var,请帮助我修复代码以使其正常工作。
我将为您提供详细的代码,输入和输出以寻求帮助。如下:
function sendArticleCountEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("STEP2 Send-Emails"));
var sheet= SpreadsheetApp.getActiveSheet()
var startRow = 2;
var numRows = sheet.getLastRow();
var dataRange = sheet.getRange(startRow, 1, numRows,
sheet.getLastColumn());
var data = dataRange.getValues();
for (i in data) {
var rowData = data[i];
if(!rowData[1]) continue;
if(rowData[3] != false) continue;
var emailAddress = rowData[1];
var recipient = rowData[0];
var parameter1 = rowData[2];
var subject = sheet.getRange(2,9).getValue();
var nbd = sheet.getRange(2,10).getValue();
var nkt = sheet.getRange(2,11).getValue();
var deadline = sheet.getRange(2,12).getValue();
var options = {
htmlBody: <body aria-readonly="false" style="cursor: auto;"><span style="font-size:16px"><span style="font-family:verdana,geneva,sans-serif"><span style="background-color:rgb(255, 255, 255); color:rgb(34, 34, 34)">Dear <strong>recipient</strong>,<br />
<br />
We would like to share with you the schedule of next week, from <strong>nbd</strong> to <strong>nkt</strong> as below: </span></span></span><br />
<br />
parameter1
<br />
<span style="font-size:16px"><span style="font-family:verdana,geneva,sans-serif"><span style="background-color:rgb(255, 255, 255); color:rgb(34, 34, 34)">Please take a look and feedback this mail to confirm that you cover these class information next week and deliver to your teachers.<br />
Looking forward to seeing your <em><strong>CONFIRMATION ASAP</strong></em>, and please before <strong>14:00, deadline</strong>.<br />
<br />
Thanks & best regards,<br />
STEMHOUSE</span></span></span></body>
};
MailApp.sendEmail(emailAddress, subject, '',options)
var completeRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn()).check()
}}
答案 0 :(得分:0)
尝试将您的options
更改为此:
var options = {
htmlBody: <body aria-readonly="false" style="cursor: auto;"><span style="font-size:16px"><span style="font-family:verdana,geneva,sans-serif"><span style="background-color:rgb(255, 255, 255); color:rgb(34, 34, 34)">Dear <strong>" + recipient + "</strong>,<br />
<br />
We would like to share with you the schedule of next week, from <strong>" + nbd + "</strong> to <strong>" + nkt + "</strong> as below: </span></span></span><br />
<br />
parameter1
<br />
<span style="font-size:16px"><span style="font-family:verdana,geneva,sans-serif"><span style="background-color:rgb(255, 255, 255); color:rgb(34, 34, 34)">Please take a look and feedback this mail to confirm that you cover these class information next week and deliver to your teachers.<br />
Looking forward to seeing your <em><strong>" + CONFIRMATION ASAP + "</strong></em>, and please before <strong>14:00, " + deadline + "</strong>.<br />
<br />
Thanks & best regards,<br />
STEMHOUSE</span></span></span></body>
};
例如,当您放置时,它会将整个HTML视为一个字符串,因此当您仅将recipients
放入其中时,它只会将其视为字符串"recipients"
,因此不是传递实际变量。