简体   繁体   中英

Google spreadsheet - sending email

please can you help me with "email" issue? I wrote code, that automatically after changing value should send email to account. Function for sending email works fine (after running from Google Script IDE) but when it should send email automatically after changing value in spreadsheet, I didn't receive any email. Please can you check my code? Debug messages are displaying fine. So I am a little bit lost.

Here is code:

function sendEmail(message) {
    Browser.msgBox(message); //Debug Message
    var emailAddress = "[email address]";
    var subject = "Sending emails from a Spreadsheet";
    MailApp.sendEmail(emailAddress, subject, message);  
}

function onEdit(event) {
  var sheet = event.range.getSheet();
  if(sheet.getName() == "Hunting List"){
    // correct sheet
    var cell = event.range;
    //var cellR = cell.getRow();  // not used at this time
    var cellC = cell.getColumn();
    var cellValue = event.value;

    if (cellC == 8) {

      if(cellValue=="Won"){
        Browser.msgBox(cellValue); //Debug Message
        sendEmail("Congratulation, we gained new client!");
      }     
    }
  }
}

For your onEdit try this

function onEdit(event) {
var sheet = event.source.getActiveSheet();
if (sheet.getName() !== "Hunting List" || event.range.columnStart !== 8) return;
if (event.value == "Won") sendEmail("Congratulation, we gained new client!");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM