簡體   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