Apps 脚本 - 通过别名发送电子邮件
Apps Script - Sending email through an alias
我编写了下面的脚本,通过别名将模板 html 电子邮件发送到 sheet 中的电子邮件列表(别名已经在我的 gmail 帐户中并且我提供了访问权限) .
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('list');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('template').evaluate().getContent();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail({
to: emailAddress,
from: "blabla@gmail.com",
subject: ('Document'),
htmlBody: html,
});
}
}
但我收到错误消息:
异常:参数 (String) 与 GmailApp.sendEmail 的方法签名不匹配。
发送电子邮件@ Code.gs:13
求助!
我检查了您的脚本,发现主要问题出在您的 GmailApp.sendEmail()
行中使用的参数结构。根据这篇关于 GmailApp class 的官方 sample for sending email via alias 文章,参数结构应该是这样的:
GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
解决方案
您可以测试这个经过调整的脚本:
已更新
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('list');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('template').evaluate().getContent();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(emailAddress, 'Document', 'Please see the message.', {
htmlBody: html,
name: "Sender Name", //On my testing, it looks "name" (Sender Name) is needed for the alias email to work and for the email to be sent to to recipient successfully
from: aliases[0]
});
}
}
我编写了下面的脚本,通过别名将模板 html 电子邮件发送到 sheet 中的电子邮件列表(别名已经在我的 gmail 帐户中并且我提供了访问权限) .
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('list');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('template').evaluate().getContent();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail({
to: emailAddress,
from: "blabla@gmail.com",
subject: ('Document'),
htmlBody: html,
});
}
}
但我收到错误消息:
异常:参数 (String) 与 GmailApp.sendEmail 的方法签名不匹配。 发送电子邮件@ Code.gs:13
求助!
我检查了您的脚本,发现主要问题出在您的 GmailApp.sendEmail()
行中使用的参数结构。根据这篇关于 GmailApp class 的官方 sample for sending email via alias 文章,参数结构应该是这样的:
GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
解决方案
您可以测试这个经过调整的脚本:
已更新
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('list');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('template').evaluate().getContent();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(emailAddress, 'Document', 'Please see the message.', {
htmlBody: html,
name: "Sender Name", //On my testing, it looks "name" (Sender Name) is needed for the alias email to work and for the email to be sent to to recipient successfully
from: aliases[0]
});
}
}