0

I"ve made a bound script scanning the records of its spreadsheet and if some conditions are true a email is sent to the appropriate employee

To be more specific the script is checking whether the list of employees are having birthday or not through a column than has true of false values.My script was working for a couple of weeks and today it stopped sending emails without changing anything

my code

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");
}
}

i check the execution transcript and it doesnt show if an email is sent.But if i use something like this it works

MailApp.sendEmail("recipient.address@gmail.com", // to
              "sender.name@gmail.com",       // from
              "Your Subject Goes Here",      // email subject
              "What ever you want to say");  // email body

Can you please help me..?thanks in advance

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
kostas.kapasakis
  • 920
  • 1
  • 11
  • 26

3 Answers3

1

First, if your sure nothing has changed in your script, I would make sure nothing has changed in your spreadsheet. If that's the case, Second I would ensure that your timestamp variable is still valid since this is a new year. Other than that, some debugging tips would be:

Since your second code block works, but not the original, I would replace one parameter at a time, progressively, from the sendEmail function that's not working with the example that is. That way you can narrow it down to the specific parameter that's failing.

I am guessing it is either going to be the "to" parameter that you might be getting wrong fields from spreadsheet, or the "email body" perhaps where your getting your images, the url might have changes, etc.

arias_JC
  • 549
  • 3
  • 15
0

instead of MailApp service try to use newer GmailApp https://developers.google.com/apps-script/reference/gmail/gmail-app

Ivan Kutil
  • 46
  • 3
0

Well, you can verify in the Google documentation on how to properly use/setup the MailApp.sendEmail.

I also found here in this SO question that the script may have a problem about the version if it is not working.

It is stated here that a version is a static copy of a script. Once a version is saved, it can no longer be modified, only deleted. This feature is used when you are working on a script that goes through many changes and iterations. Versions allow you to keep track of your changes.

For more information about this, just check the linked SO question in the answer. Hope it helps you.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31