为什么我的 google 脚本项目的 sendEmail 函数的触发器执行日志显示已完成,但没有发送实际电子邮件?

问题描述 投票:0回答:1

我正在尝试在谷歌脚本中创建一个函数,当用户在表单中输入电子邮件时,该函数会尝试自动向用户发送电子邮件。我为此设置了一个触发器,根据执行日志,我所做的尝试全部成功,但是,实际上没有电子邮件发送到我输入的测试电子邮件。下面是我的代码:



function sendEmail(e) {
var esheete = SpreadsheetApp.getActiveSpreadsheet();
  if (!e || !e.range) {
    console.error("Event object or range is missing.");
    return;
  }

  const dissheete = e.range.getSheet();


  if (e.range.columnStart == 6 && e.range.rowStart > 1) {
    
    const rowr = e.range.getRow();
    const emailAddress = dissheete.getRange(rowr, 7).getValue();
    const nonEmptyValues = getLastNonEmptyCellValues(dissheete, [2, 3, 4]);
        const teacherName = nonEmptyValues[0];
        const meetingDetails = nonEmptyValues[1];
        const meetTime = nonEmptyValues[2];
    const queueSlots = sheete.getRange(rowr, 5).getValue();
    const queueEntryName = e.value;
    const subject = "Academic Advising Schedule: Slot Confirmation";
    const message = "Greetings, " + queueEntryName + "!\n\n" +
                    "You have been added to the meeting queue. Please take note of the meeting's details. \n\n" +
                    "Meeting with: Mr/Ma'am " + teacherName + "\n" +
                    "Meeting Details: " + meetingDetails + "\n" +
                    "Meeting Time: " + meetTime + "\n" +
                    "Queue Slot: " + queueSlots + "\n\n" +
                    "Please keep a copy of this message, and take note of the time when you received this. In case someone replaces your name in the Queueing Sheet, please present this confirmation email to your adviser." +
                    "Please make sure to attend the said schedule. Thank you!";
    
    GmailApp.sendEmail(emailAddress, subject, message);
  }
}

function getLastNonEmptyCellValues(dissheete, columns) {
  var lastRow = dissheete.getLastRow();
  var nonEmptyValues = [];

  // Iterate over each column in the array
  columns.forEach(function(column) {
    for (var i = lastRow; i > 0; i--) {
      var cellValue = dissheete.getRange(i, column).getValue();
      if (cellValue !== "") {
        nonEmptyValues.push(cellValue); // Store non-empty value
        break; // Move to the next column
      }
    }
  });

  return nonEmptyValues;
}

我已经尝试删除并重新启动触发器,但没有任何反应。

javascript google-sheets google-apps-script triggers
1个回答
0
投票

虽然我不确定你的实际电子表格,但如果你的显示脚本是你的整个脚本,我认为

sheete
const queueSlots = sheete.getRange(rowr, 5).getValue();
没有声明。我猜这可能是您当前问题的原因。

在您的情况下,

sheete
dissheete
?我认为
esheete
dissheete
是一样的。如果我的理解正确,请修改如下并再次测试。

来自:

const queueSlots = sheete.getRange(rowr, 5).getValue();

致:

const queueSlots = dissheete.getRange(rowr, 5).getValue();
© www.soinside.com 2019 - 2024. All rights reserved.