我对 Google Apps 脚本完全陌生,正在尝试完成应该是来自 gmail 的相当基本的邮件合并。我已经下载了一个 99% 正确工作的脚本和模板,但是,它不允许用户调整电子邮件来自的电子邮件地址或帐户。我有几个链接到我的 gmail 帐户的电子邮件帐户,这个脚本只允许我使用我的 gmail 域帐户 (myname@gmail.com) 发送。有谁知道我如何编辑以下代码以允许使用我的替代链接帐户(myname@domain.com)?编码:
function onOpen() {
var mySheet = SpreadsheetApp.getActiveSpreadsheet();
mySheet.addMenu('Mail Merge', [{name:'Send Emails', functionName:'sendEmail'}]);
}
function sendEmail() {
//Get Sheet
var mySheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var rowCount = mySheet.getLastRow();
//Get Basic Email Data
var emSubject = mySheet.getRange('K2').getValue();
var emFromName = mySheet.getRange('K3').getValue();
var emFrom = mySheet.getRange('K4').getValue();
//Build Email Body
var emBody = '';
var textFound = false;
for (var i=rowCount; i>=6; i--) {
var line = mySheet.getRange('J' + i).getValue();
if (line != '' || textFound) {
emBody = line + '<br/>' + emBody;
textFound = true;
}
}
//Process Emails
var remainingQuota = MailApp.getRemainingDailyQuota();
remainingQuota = remainingQuota;
var emailsSent = 0;
for (var i=3; i<=rowCount; i++) {
var emTo = mySheet.getRange('B' + i).getValue();
if (emTo != '' && mySheet.getRange('A' + i).getValue() == '') {
if (remainingQuota > 0) {
//Add Merge Fields To Body
var thisEmBody = emBody;
thisEmBody = thisEmBody.replace(/\[GreetingName\]/g, mySheet.getRange('C' + i).getValue());
thisEmBody = thisEmBody.replace(/\[DATA2\]/g, mySheet.getRange('D' + i).getValue());
thisEmBody = thisEmBody.replace(/\[DATA3\]/g, mySheet.getRange('E' + i).getValue());
thisEmBody = thisEmBody.replace(/\[DATA4\]/g, mySheet.getRange('F' + i).getValue());
thisEmBody = thisEmBody.replace(/\[DATA5\]/g, mySheet.getRange('G' + i).getValue());
thisEmBody = thisEmBody.replace(/\[DATA6\]/g, mySheet.getRange('H' + i).getValue());
//Send Emails
MailApp.sendEmail(emTo, emSubject, thisEmBody, { htmlBody:thisEmBody, name:emFromName, replyTo:emFrom })
mySheet.getRange('A' + i).setValue('Sent');
remainingQuota--;
emailsSent++;
} else {
mySheet.getRange('A' + i).setValue('QUOTA EXCEEDED');
}
SpreadsheetApp.flush();
}
}
Browser.msgBox(emailsSent + ' email' + ((emailsSent!=1)?'s':'') + ' sent.' + ((emailsSent==0) ? ' - Please make sure the status column (A) is empty and there are email addresses in column B' : ''))
}
我环顾四周,但无法确定解决方案。任何帮助将不胜感激!