2016-07-25 59 views
0

我嘗試運行此腳本,但未發送任何電子郵件至useremail。當用戶選擇1,2,3和頂點時,這個腳本將比較工作表(第10列)中的值併發送差異電子郵件正文。按照這個腳本發送電子郵件與表中的值進行比較

function mutisendemail(e) { 
 
if (e.values[10] == "1") { 
 
    var useremail = "[email protected]"; 
 
    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 = "[email protected]"; 
 
    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 = "[email protected]"; 
 
    var subject = "test3"; 
 
    var body = "number3"; 
 
    var photo = DriveApp.getFilesByName('test1.jpg'); 
 
    MailApp.sendEmail({ 
 
     to: userEmail, 
 
     subject: subject, 
 
     body: body, 
 
     attachments: [photo.next()] 
 
    }); 
 
} 
 
}

+0

請讓代碼可讀性 - [這](http://jsbeautifier.org/)是一個在線資源,你可以用它來縮進代碼正確 –

+0

顯示在開發商有哪些誤區工具控制檯 –

+0

它顯示TypeError:無法從undefined讀取屬性「值」。 (第2行,文件「測試」) –

回答

1

請注意,變量useremailuserEmail寫不同。當我確定我收到我的收件箱中的電子郵件時。 這是全碼:

function sendSimpleEmail(mynumber){ 
    var useremail = "[email protected]"; 
    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"); 
    } 
+0

謝謝你,但它仍然不起作用。感謝您的評論 –

+0

請問您可以添加e定義的代碼嗎? – Eugene