我尝试运行此脚本,但它没有向useremail发送任何电子邮件。当用户选择1,2,3和Summit时,此脚本将比较工作表(第10列)和发送的差异电子邮件正文中的值。请关注此脚本
function mutisendemail(e) {
if (e.values[10] == "1") {
var useremail = "test@gmail.com";
var subject = "test1";
var body = "number 1 ";
var photo = DriveApp.getFilesByName('test1.jpg');
MailApp.sendEmail({
to: userEmail,
subject: subject,
body: body,
attachments: [photo.next()]
});
}
if (e.values[10] == "2") {
var useremail = "test@gmail.com";
var subject = "test2";
var body = "number2";
var photo = DriveApp.getFilesByName('test1.jpg');
MailApp.sendEmail({
to: userEmail,
subject: subject,
body: body,
attachments: [photo.next()]
});
}
if (e.values[10] == "3") {
var useremail = "test@gmail.com";
var subject = "test3";
var body = "number3";
var photo = DriveApp.getFilesByName('test1.jpg');
MailApp.sendEmail({
to: userEmail,
subject: subject,
body: body,
attachments: [photo.next()]
});
}
}
答案 0 :(得分:1)
请注意,变量useremail
和userEmail
的编写方式不同。当我确定我收到了收件箱中的电子邮件。
这是完整的代码:
function sendSimpleEmail(mynumber){
var useremail = "myemail@gmail.com";
var subject = "test"+mynumber;
var body = "number "+mynumber;
var photo = DriveApp.getFilesByName('MyFile.pdf');
MailApp.sendEmail({
to: useremail,
subject: subject,
body: body,
attachments: [photo.next()]
});
}
function sendConditionalEmail(){
var mySheet = SpreadsheetApp.getActiveSpreadsheet();
var myCell = 'B5';
var cellValue = mySheet.getRange(myCell).getValue();
if(cellValue=="1"){
sendSimpleEmail("1");
}
else if(cellValue=="2"){
sendSimpleEmail("2");
}
else if(cellValue=="3"){
sendSimpleEmail("3");
}