MailApp:CC和BCC邮件中的动态变量不起作用 [英] MailApp: Dynamic variables in CC and BCC mail is not working

查看:99
本文介绍了MailApp:CC和BCC邮件中的动态变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动发送电子邮件. 我在Google表格中有一个查询,该查询向我显示了必须发送电子邮件的所有情况. for循环收集相应的客户名称,电子邮件,VIN,电话等.电子邮件的主题和正文用来自Google工作表的正确数据替换{name},{VIN}等.到目前为止,该方法仍然有效,但是当我将某人放入抄送或密件抄送中时,抄送或密件抄送电子邮件的变量不会更改. 主题中的输出为空,并且在电子邮件正文中以{name}等显示,而不是正确的客户名称.

I am trying to automated emails. I have a query in google sheets that displays me all cases where an email has to be sent. The for loop collects the corresponding customer name, email, VIN, telephone etc.. The subject and body of the email replaces {name}, {VIN} etc. with the correct data from the google sheet. This works so far, but when I put someone in CC or BCC the variables don't change for the CC or BCC email. The output in the subject is empty and in the email body it is displayed with {name} etc. instead the correct customer name.

发给CC/BCC的邮件也应显示正确的变量,我该如何解决.

The mails to the CC/BCC should also display the right variables, how can I fix this.

这是我的代码:

function sendEmails() {
  
  var scriptInfo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("script_info");
  var scriptInfoMail = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("script_info_MAIL");
  var lr = scriptInfo.getLastRow();
  var templateText = scriptInfoMail.getRange(5,2).getValue();
  
  
  //get attachments
  var folderIter = DriveApp.getFoldersByName("Logistics2.0");
  var folder = folderIter.next();
  var file1Iter = folder.getFilesByName("Übergabeprotokoll.pdf");  
  var file1 = file1Iter.next();
  var file2Iter = folder.getFilesByName("....._03.pdf");  
  var file2 = file2Iter.next();
  
  
    for (var i = 2; i<=lr;i++){
      
      //loops through open Deal_IDs for personal info
      var currentDealId = scriptInfo.getRange(i, 1).getValues();
      var currentCustomerEmail = scriptInfo.getRange(i, 5).getValue();
      var currentEmEmail = scriptInfo.getRange(i, 12).getValue();
      var currentTelefon = scriptInfo.getRange(i, 6).getValues();
      var currentVIN = scriptInfo.getRange(i, 7).getValues();
      var currentDateEta = scriptInfo.getRange(i, 8).getDisplayValue();
      var currentName = scriptInfo.getRange(i, 10).getValues();
      var currentAbholNR = scriptInfo.getRange(i, 11).getValues();
      
      //email Subject and Body
      var subjectLine = "Anlieferung VEHICULUM-Fahrzeug VIN: " + currentVIN + " / " + currentDealId;
      
      var htmlTemplate = HtmlService.createHtmlOutputFromFile("htmlTemplate") // Generate the HTML
      .getContent();
      
      var messageBody = htmlTemplate.replace(/{VIN}/g, currentVIN) //replaces VIN
      .replace(/{Name}/g, currentName) //replaces Customer Name
      .replace(/{ETA EM}/g, currentDateEta) //replaces ETA Euromaster
      .replace(/{KundenEmail}/g, currentCustomerEmail) //replaces Customer Email
      .replace(/{Telefon}/g, currentTelefon) //replaces Customer Telephone
      .replace(/{Abholnummer Kunde}/g, currentAbholNR); //replaces Abholnummer
      
       Logger.log(messageBody);
      
      MailApp.sendEmail({
        to: currentEmEmail, 
        subject: subjectLine, 
        htmlBody: messageBody, 
        cc: "p........@......",
        attachments: [file1, file2]});
    }
  }
}

推荐答案

答案:

您需要对options参数中的BCC和CC使用sendEmail(recipient, subject, body, options)方法.

Answer:

You need to use the sendEmail(recipient, subject, body, options) method with the BCC and CC in the options parameter.

根据文档:

sendEmail(recipient, subject, body, options)

发送带有可选参数的电子邮件.

Sends an email message with optional arguments.

在高级参数"部分:

bcc String:以逗号分隔的发给密件抄送电子邮件地址的列表

bcc String: a comma-separated list of email addresses to BCC

cc String:发送给抄送的电子邮件地址的逗号分隔列表

cc String: a comma-separated list of email addresses to CC

代码修改:

MailApp.sendEmail({to: currentEmEmail, 
        subject: subjectLine, 
        htmlBody: messageBody, 
        cc: "p........@......",
        attachments: [file1, file2]});

应该是:

MailApp.sendEmail(currentEmEmail, subjectLine, messageBody, {
  cc: "p........@......",
  name: 'Automatic Emailer Script',
  attachments: [file1, file2]
});

希望对您有帮助!

这篇关于MailApp:CC和BCC邮件中的动态变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆