google-apps-script - 使用 cc 发送电子邮件的 Google 表格不起作用
问题描述
我正在尝试创建一个脚本,将带有 cc 的工作表的 PDF 副本发送到另一封电子邮件,当我发送电子邮件时它可以工作,但 cc 电子邮件没有收到任何内容,故障可能出在哪里?
function emailSpreadsheetAsPDF() {
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Invoice").getRange("G8");
var email = emailRange.getValues();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Invoice"); // Enter the name of the sheet here
var subject = "Your Little Kid's " + ss.getName();
var body = "\n Please see attached a copy of your invoice";
// Base URL
var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", ss.getId());
/* Specify PDF export parameters
From: https://code.google.com/p/google-apps-script-issues/issues/detail?id=3579
*/
var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls / xlsx
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=true' // orientation, false for landscape
+ '&fitw=true&source=labnol' // fit to page width, false for actual size
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenumbers=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&gid='; // the sheet's Id
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url + url_ext + sheet.getSheetId(), {
headers : {
'Authorization' : 'Bearer ' + token
}
}).getBlob().setName(sheet.getName() + ".pdf");
// Uncomment the line below to save the PDF to the root of your drive.
// var newFile = DriveApp.createFile(response).setName(sheet.getName() + ".pdf")
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, subject, body, {htmlBody : body,attachments : [response], cc: 'myemail@mailtest.com'});
}
解决方案
推荐阅读
- javascript - 编译后是否可以监听组件的 React 渲染(例如在浏览器控制台中)?
- aws-api-gateway - AWS CDK:如何在一个 API 中合并 Legacy swagger 和 CDK 定义的资源?
- python - 用python计算文件中的字母和单词
- python - Python 基础 - ps.tekken() = '对象没有属性'
- bash - 批量更新 YAML 文件特定组件
- c++ - 将 R studio 链接到 C++ boost 库(windows)
- react-native - 如何使用弹性盒在口粮中划分屏幕
- vue.js - Rollup,Vue 和 Buble,scss 文件中的意外标记
- .net - 如何使用 Newtonsoft.JSON 递归生成 JSON 模式?
- python - 完全向量化切片矩阵乘法