繁体   English   中英

使用辅助帐户在Gmail中邮件合并

[英]Mail merge in gmail using secondary account

我是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' : ''))

}

我已经看了一下但是无法确定解决方案。 任何帮助将不胜感激!

如果您改为使用GmailApp.sendEmail() ,则可以获得该功能。 请参阅文档

您只需将from:"yourOtherEmail@domain.com"添加到advancedArgs即可。

您可以使用GmailApp.getAliases()查询可以使用的别名。

从阅读你的问题来看,你的@domain@gmail帐户的别名是不明确的...如果没有,规则很简单:邮件是使用脚本所有者的帐户发送的,所以你唯一需要做的就是在@domain帐户中创建脚本,邮件将自动从此帐户发送。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM