简体   繁体   English

Google电子表格-发送电子邮件

[英]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. 发送电子邮件的功能运行良好(从Google Script IDE运行后),但是在更改电子表格中的值后应自动发送电子邮件时,我没有收到任何电子邮件。 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 为了您的onEdit尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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