2016-07-25 6 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:プロパティ "values"を未定義から読み取ることができません。 (2行目、 "test"ファイル) –

答えて

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

関連する問題