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

Google Apps Script中MailApp.sendEmail误发至自身收件箱问题求助

谷歌脚本发邮件同时出现在已发送和收件箱的问题

我有一个用于向谷歌表格列表中所有邮箱发送邮件的Google Apps Script脚本,已正常使用1年多,但近几个月运行时,邮件不仅会存入已发送文件夹,还会发送至我的收件箱。试过替换MailApp.sendEmail为GmailApp.sendEmail、检查邮件过滤器这两种方案,均未解决问题。

相关脚本如下:

function arrayUnique(arr) {
  var tmp = [];
  // filter out duplicates
  return arr.filter(function(item, index){
    var stringItem = item.toString(); // convert row arrays to strings for comparison
    tmp.push(stringItem); // push string items into temporary arrays
    return tmp.indexOf(stringItem) >= index; // only return the first occurrence of the strings
  })}

function sendEmail() {
  var sheet = SpreadsheetApp.getActive().getSheetByName("pending list")
  var sub = "Error Fix Required"
  var data = sheet.getRange(3,1, sheet.getLastRow(), 5).getDisplayValues().filter(function (row){
    var date = sheet.getRange(1,2).getDisplayValues()
    return row[3] == date
  })
  var filterunique = arrayUnique(data)
  var json = {}
  filterunique.forEach(function (item){
    if(item[2] || item[2].length > 0){
    if(!json[item[2]]){
      json[item[2]] = []
    }
    json[item[2]].push(item[0])
    }
  })
  Object.keys(json).forEach(function(to){
    var email = "{{user}}@shopee.com"
    email = email.replace(/{{user}}/gi,to)
    var sku = "<br><ul><li>" + json[to].join("</li><li>") + "</li></ul>"
    var body = "Hi " + to +", <br><br>The following require your kind attention:" + sku + "Please go to this <a href='https://docs.google.com/spreadsheets/d/1nMKeW//'>link</a> to rectify your submissions by today 4pm.<br><br> Thanks."
    MailApp.sendEmail({
    to: email,
    subject: sub,
    htmlBody: body
  });
  })
}

收件箱中收到该邮件的截图:
收件箱邮件截图
收件箱邮件详情截图

内容的提问来源于stack exchange,提问作者Kreng Kongkeng

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 00:55:54