You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google表单提交新增行触发邮件自动回复,脚本报无收件人错误求助

问题分析与解决方案

核心错误:MailApp.sendEmail 参数顺序错误

你遇到的「没有收件人」错误,本质是调用MailApp.sendEmail时参数传递顺序不对。该方法的标准参数逻辑是:收件人、主题、正文为必填项,回复邮箱这类配置属于可选参数,需要放在配置对象中,而非直接作为第二个参数传入。你的写法导致系统错误识别参数,引发逻辑混乱。

修正后的脚本

方式1:用配置对象传递所有参数(更清晰)

function sendConfirmationEmail() {
  const ss = SpreadsheetApp.openById('SHEET-ID');
  const sheet = ss.getSheetByName('UPDATED');
  const lastRow = sheet.getLastRow();
    
  const email_recipient = sheet.getRange(lastRow, 34).getValue();
  const reply_to = sheet.getRange(lastRow, 35).getValue();
  const email_subject = sheet.getRange(lastRow, 36).getValue();
  const email_body = sheet.getRange(lastRow, 37).getValue();

  // 通过配置对象明确各参数含义
  MailApp.sendEmail({
    to: email_recipient,
    replyTo: reply_to,
    subject: email_subject,
    body: email_body
  });
}

方式2:按标准参数顺序传递

function sendConfirmationEmail() {
  const ss = SpreadsheetApp.openById('SHEET-ID');
  const sheet = ss.getSheetByName('UPDATED');
  const lastRow = sheet.getLastRow();
    
  const email_recipient = sheet.getRange(lastRow, 34).getValue();
  const reply_to = sheet.getRange(lastRow, 35).getValue();
  const email_subject = sheet.getRange(lastRow, 36).getValue();
  const email_body = sheet.getRange(lastRow, 37).getValue();

  // 按「收件人→主题→正文→配置对象」的顺序传递
  MailApp.sendEmail(email_recipient, email_subject, email_body, {
    replyTo: reply_to
  });
}

额外检查项

  • 确认第34列(对应getRange(lastRow, 34))的单元格存在有效邮箱地址,无空值或格式错误;
  • 检查lastRow是否指向有数据的行,避免表格末尾空行导致取到空收件人;
  • 首次运行脚本时需完成授权流程,确保脚本拥有发送邮件的权限。

内容的提问来源于stack exchange,提问作者Analyst-at-Heart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 04:25:38