带输入框的邮件合并脚本

时间:2012-10-27 10:18:52

标签: google-apps-script mailmerge

我正在尝试从电子表格中的模板中更改一个单词,以获取用户通过输入框输入的值。当我运行我的脚本时它不会改变这个词,任何想法??

function sendEmails() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
var time = Browser.inputBox("Enter TIME");
var address = "albdominguez25@gmail.com";
ss.setActiveSheet(ss.getSheetByName("Templates"));
var emailTemplate = ss.getRange("B1").getValue();
//here I am trying to replace the word "TIME" on my template to the value entered on             the inputBox
emailTemplate.replace("TIME",time);
var emailSubject = "Tutorial: Simple Mail Merge";    

MailApp.sendEmail(address, emailSubject, emailTemplate);

}

1 个答案:

答案 0 :(得分:2)

毕,

我认为您的替换来源并未将emailTemplate.replace的结果分配给变量。

我还对SpreadsheetApp调用做了一点点。当然,取决于你的目标。

吉姆

function sendEmails() {
  var emailTemplate = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("B1").getValue();
  var time = Browser.inputBox("Enter TIME");
  var address = "jcampbell@neonova.net";
  emailTemplate = emailTemplate.replace("TIME",time);
  var emailSubject = "Tutorial: Simple Mail Merge";    

  MailApp.sendEmail(address, emailSubject, emailTemplate);
}