当在列O单元格中提到“已发货”时,我想在C列发送电子邮件(带有相应的行)
需要支持才能使此脚本正确
function sendEmail(e) {
var thisSheet = e.source.getActiveSheet();
if (thisSheet.getName() !== 'CRM' || e.range.columnStart !== 15 || e.range.rowStart == 1 || e.value !== 'Shipped') return;
var body, headers = thisSheet.getRange(1, 1, 1, 6)
.getValues()[0],
thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 6)
.getValues()[0],
recipientsEMail = (thisSheet.getRange.columnStart !==3 || e.range.rowStart ==1)
.getValues()[0],
recipients = recipientsEMail,
subject = "Your Vehicle is shipped " + e.source.getName(),
body = "",
i = 0;
while (i < 6) {
body += headers[i] +' - ' + thisRow[i] +'\n';
i++;
}
MailApp.sendEmail(recipients, subject, body);
}
答案 0 :(得分:2)
看看是否有效:
function sendEmail(e) {
var thisSheet = e.source.getActiveSheet();
if (thisSheet.getName() !== 'CRM' || e.range.columnStart !== 15 || e.range.rowStart == 1 || e.value !== 'Shipped') return;
var body, headers = thisSheet.getRange(1, 1, 1, 15)
.getValues()[0],
thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 15)
.getValues()[0];
var recipients = thisRow[2];
var subject = "Your Vehicle is shipped " + e.source.getName(),
body = "Dear Customer,\n\nYour vehicle has been shipped from Japan";
MailApp.sendEmail(recipients, subject, body);
}
您没有说明需要使用多少列来构建电子邮件正文,但如果增加while循环中的数字,则可以轻松更改这些列。