Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29755

MailApp.sendEmail function runs without errors but no emails are sent

$
0
0

The below script runs without any visible error, but no emails are sent. Any ideas as to why?

function sendEmailLoop() {  var sheets =   SpreadsheetApp.getActiveSpreadsheet().getSheets();  sheets.forEach(function(sheet) {    var range = sheet.getDataRange();    if (sheet.getName() == "Summary") //Disregard tab named 'Summary'    {          }    else {          var range = sheet.getDataRange(); //to set the range as array      var values = range.getDisplayValues(); //to get the value in the array      var lastRow = range.getLastRow();      var ss = SpreadsheetApp.getActiveSpreadsheet();  //declare the spreadsheet      var sheet = ss.getSheetByName("Sheet1");      var Title = values[0][0];         //[Title] cell A1      var URL = values[0][1];           //[URL] cell B1      var i;      var logContent = '';      for (i = 3; i < lastRow; i++) {           var Name = values[i][0];     //[Name] cell A++        var Email = values[i][1];        // [Email] cell B++        Logger.log('to: '+ Email);        Logger.log('subject: '+ Name + Title +'Test');        Logger.log('message: '+'This is a test message for the training that can be found at '+ URL);        /*        MailApp.sendEmail({          to: Email,          subject: Name + Title +'Test',          message: 'This is a test message for the training that can be found at '+ URL});        */      }; //end for loop - email tab data    };   // end 'else'  }); // end function(sheet)       } // end SendEmailLoop()  

Here is the Stackdriver log of a successful execution (success meaning no errors, but still no emails are sent):

Stackdriver log

The structure of the spreadsheet associated with the script:

spreadsheet associated with the script

Note - an earlier version of this script didn't include the sheets.forEach() method call (ie, to loop through each tab of the spreadsheet) and the emails were sent fine.

Could the lack of emails being sent or received be related to the fact that I have many sheets and this function is looping through them?


Viewing all articles
Browse latest Browse all 29755

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>