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

GmailApp.sendEmail的'from'参数失效问题排查与解决

问题:Google Apps Script无法指定自定义发件人发送邮件?

问题场景

使用Google Workspace账号运行Google Apps Script时,尝试用以下代码指定发件人发送邮件,但所有邮件默认都用主账号me@mydomain.nl发送:

GMailApp.sendEmail('me@mydomain.nl','Subject of this email',Logger.getLog(),
     {name:'Save attachments from triggered attachment script',from:'logging@mydomain.nl'} 

已确认logging@mydomain.nl是账号的别名,在Gmail客户端可以正常用该地址发信,调整“视为别名”选项、更换其他别名也无效。

解决方案

经排查发现核心问题:实际代码中误将GMailApp写成了MailApp——MailApp.sendEmail()不支持from参数覆盖发件人,而GmailApp.sendEmail()完全支持指定账号已配置的别名作为发件人。将代码中的MailApp替换为GmailApp后,即可正常使用指定的发件人地址发送邮件。

内容的提问来源于stack exchange,提问作者Peter Berkhout

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 23:27:02