2017-01-09 54 views
0

我「犯了一個綁定腳本掃描其電子表格的記錄,如果某些條件,則電子郵件被髮送到合適的員工MailApp.sentEmail L不工作了(谷歌應用程序腳本)

更具體的腳本是通過檢查列表的員工是否有生日或沒有真正的假值。我的腳本工作了幾個星期,今天它停止發送電子郵件而不改變任何東西

我的代碼

function send() { 

//returns the current active spreadsheet 
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 
var sheet = spreadsheet.getActiveSheet(); 


var recipient; 
var startRow = 2; // First row of data to process 
var lastRow = sheet.getLastRow();//Last row to process ,the EOF 
var emailSend = "FALSE";//flag to know if the mail has been sent 
var d = new Date();//saving the date 
var timeStamp = d.getYear();//specifing the years section 



//take images location 
var wishes_imageURL ="http://dekhnews.com/wp-content/uploads/...       nielsen_imageURL="http://www.nielsen.com/content/dam/nielsenglobal/us 

//change them to objects blobs 
var wishesBlob = UrlFetchApp 
         .fetch(wishes_imageURL) 
         .getBlob() 
         .setName("wishesBlob"); 
var nielsenBlob = UrlFetchApp 
         .fetch(nielsen_imageURL) 
         .getBlob() 
         .setName("nielsenBlob"); 


//for every employee that the 4rth column is true(has_birthday) send email to his/her email address 
    for (var i =startRow ; i <= lastRow; i++) { 

//take info about if the birthday mail has been send before to the employee 
emailSend = sheet.getRange(i, 6).getValue(); 

//whoever has birthday and havent get email before send him/her mail 
if((sheet.getRange(i, 5).getValue() == true) && (emailSend !="TRUE") && (timeStamp == sheet.getRange(1, 7).getValue())){ 

recipient = sheet.getRange(i, 4).getValue(); 
    MailApp.sendEmail(sheet.getRange(i, 4).getValue(), 
        "", 
        "BirthDay Wishes", 

    { htmlBody:"<h3 style='text-align:center; color:blue;'><i>" + "Για τα γενέθλιά σου ευχόμαστε ολόψυχα Χρόνια Πολλά και κάθε προσωπική και επαγγελματική επιτυχία!" + 
           "</i></h3>" + "<center><img src='cid:wishes' style='width:500px; height:450px; align:center; position:relative; '/></center>" + "\n" + 
           "<h3 style = 'text-align:center;color:blue;'>" + "Βίκη – Σπύρος &" +"\n" + "Δ/νση Ανθρώπινου Δυναμικού" + "</h3>" + "\n" 
           + "\n\n\n\n"+ "<center><img src='cid:nielsen'/></center>", 
           inlineImages: 
           { 
            wishes: wishesBlob, 
            nielsen: nielsenBlob 
           } 
        }); 


    //after we sent the mail we "lock" this emplyee for the current year 
    sheet.getRange(i,6).setValue("TRUE"); 
} 
} 

我檢查執行成績單和它不顯示在郵件的sent.But如果我使用像這樣它的工作原理

MailApp.sendEmail("[email protected]", // to 
       "[email protected]",  // from 
       "Your Subject Goes Here",  // email subject 
       "What ever you want to say"); // email body 

能否請你幫我......?在此先感謝

回答

1

首先,如果你確保沒有在你的腳本發生了變化,我會確保沒有在您的電子表格已經改變。如果是這樣,第二我會確保你的timestamp變量仍然有效,因爲這是新的一年。除此之外,一些調試技巧將是:

由於您的第二個代碼塊的作品,但不是原來的,我會逐步替換sendEmail功能,這是不適用於該示例的一個參數。這樣你可以縮小到失敗的特定參數。

我猜測它要麼將成爲「」的參數,你可能會得到來自電子表格錯誤的領域,或「電子郵件正文」也許在您獲得您的圖片,網址可能有變化等

0

那麼,您可以驗證在谷歌documentation如何正確使用/設置MailApp.sendEmail

我也在這裏找到SO question這個腳本,如果它不工作,腳本可能會有版本問題。

聲明here版本是腳本的靜態副本。版本保存後,不能再進行修改,只能刪除。此功能用於處理經歷許多更改和迭代的腳本。版本允許您跟蹤您的更改。

有關這方面的更多信息,只需檢查答案中鏈接的SO問題。希望它可以幫助你。

相關問題