【问题标题】:I need to add a second email address to this function from Google sheets我需要从 Google 表格向此功能添加第二个电子邮件地址
【发布时间】:2021-07-05 19:01:09
【问题描述】:

我有这个脚本,可以将电子邮件发送到在 Google 电子表格的“E6”单元格中输入的电子邮件地址。我还需要同时将副本发送到另一个电子邮件地址。你能帮我弄清楚如何修改这段代码来做到这一点吗?非常感谢您的帮助。

function sendSheetToPdfwithA1MailAdress(){ // this is the function to call
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0]; // it will send sheet 0 which is the first sheet in the spreadsheet.
  // if you change the number, change it also in the parameters below
  var shName = sh.getName()
  sendSpreadsheetToPdf(0, shName, sh.getRange('E6').getValue(),"Balance Over Burnout", "The attached PDF contains a copy of your personalized Wellness Wheel, and the answers to your questionnaire.");
 
}
function sendSpreadsheetToPdf(sheetNumber, pdfName, email,subject, htmlbody) {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var spreadsheetId = spreadsheet.getId()  
  var sheetId = sheetNumber ? spreadsheet.getSheets()[sheetNumber].getSheetId() : null;  
  var url_base = spreadsheet.getUrl().replace(/edit$/,'');

  var url_ext = 'export?exportFormat=pdf&format=pdf'   //export as pdf

      + (sheetId ? ('&gid=' + sheetId) : ('&id=' + spreadsheetId)) 
      // following parameters are optional...
      + '&size=A4'      // paper size
      + '&portrait=true'    // orientation, false for landscape
      + '&fitw=true'        // fit to width, false for actual size
      + '&sheetnames=true&printtitle=false&pagenumbers=true'  //hide optional headers and footers
      + '&gridlines=false'  // hide gridlines
      + '&fzr=false';       // do not repeat row headers (frozen rows) on each page

  var options = {
    headers: {
      'Authorization': 'Bearer ' +  ScriptApp.getOAuthToken(),
    }
  }

  var response = UrlFetchApp.fetch(url_base + url_ext, options);
  var blob = response.getBlob().setName(pdfName + '.pdf');
  if (email) {
    var mailOptions = {
      attachments:blob, htmlBody:htmlbody
    }
MailApp.sendEmail(
      email, 
      subject+" (" + pdfName +")", 
      "html content only", 
      mailOptions);

MailApp.sendEmail(
      Session.getActiveUser().getEmail(), 
      "FRWD "+subject+" (" + pdfName +")", 
      "html content only", 
      mailOptions);

【问题讨论】:

    标签: javascript email pdf google-sheets


    【解决方案1】:

    MailApp.sendEmail 方法将第一个参数作为“收件人地址,以逗号分隔” 我希望这个文档链接可以帮助您进一步了解 API。 https://developers.google.com/apps-script/reference/mail/mail-app

    【讨论】:

    • 非常感谢!
    • 如果它解决了您的问题,您能否将答案投票为“这个答案很有用”而不是“这个答案没用”?
    • @Jiffyjjackson 请接受这个答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 2021-11-08
    • 1970-01-01
    • 2020-11-27
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多