I have written a script that attaches the content of the sheet as an attachment and emails it.
This is for invoicing. Once an invoice is generated, the invoice is sent as a PDF to the vendor. Now, i want these sent invoices documented in google drive every time they are sent
Now, i want this attachment PDF to be saved to a google drive folder every time the email is triggered
This is an invoicing sheet.
function emailSpreadsheetAsPDF() {
const sheetToPrint = "Invoice"; // name of the sheet to print
const ss = SpreadsheetApp.getActiveSpreadsheet(); // the sheets to use
const subject = `Invoice`; // the subject of the email
const shID = ss.getSheetByName(sheetToPrint).getSheetId(); // the ID of the sheet
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ss.getId()); // url of the spreadsheet
const exportOptions =
'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=A4'+ // size of the PDF (legal / A4 / letter)
'&portrait=true'+ // orientation of the PDF (false for landscape)
'&fitw=true'+ // 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='+shID; // the sheet's Id
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
// generate the PDF file
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
var ui = SpreadsheetApp.getUi();
var resp = ui.alert('Are you sure?',ui.ButtonSet.YES_NO);
if(resp == ui.Button.YES)
{
var ssheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Invoice");
var tsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Invoice Archives");
var tindex = tsheet.getLastRow();
var count = tsheet.getRange(tindex,1).getValue();
tindex = Number(tindex) + 1;
var count = tsheet.getRange(tindex,1).setValue(Number(count)+1);
ssheet.getRange(22,8).copyTo(tsheet.getRange(tindex,7), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false); //Invoice Amout
ssheet.getRange(7,8).copyTo(tsheet.getRange(tindex,15), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ssheet.getRange(21,8).copyTo(tsheet.getRange(tindex,16), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
ssheet.getRange(10,8).copyTo(tsheet.getRange(tindex,17), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false); // admin name
ssheet.getRange(11,8).copyTo(tsheet.getRange(tindex,18), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false); // admin email
ssheet.getRange(12,8).copyTo(tsheet.getRange(tindex,19), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false); // sales lead email
var invid = tsheet.getRange(tindex,2).getValue();
var invamount = tsheet.getRange(tindex,7).getValue();
var adminname = tsheet.getRange(tindex,17).getValue();
var aemail = tsheet.getRange(tindex,18).getValue();
var semail = tsheet.getRange(tindex,19).getValue();
var email = aemail + ',' + semail ;
Logger.log(email);
var body = '<p>Hello '+adminname+',</p> <p>Greetings from Begig! Hope you are doing well.</p> <p>Please find an invoice attached to this email of value ₹'+invamount+'. Request you to process the payment against it at the earliest</p> <p> </p> <p>--</p> <p>Regards</p> <p>Ops Team - Begig</p>'
// send the email to the specified address with the specified body text and attached PDF file
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [{
fileName: "Invoice - "+ invid+".pdf",
content: response.getBytes(),
mimeType: "application/pdf"
}]
});
raiseinvoice();
}
}
To save the pdf, you will have to add
const folder = DriveApp.getFolderById('_______if of folder______');
folder.createFile(response.setName('______name_of_file_____'));
Related
I have this code that generates a PDF file from a Google Spreadsheet and sends it as an email attachment. The issue is that it zips the file with const zipBlob = Utilities.zip(blobs).setName('${ss.getName()}.zip');.
I want to change it so that the attached file is a PDF and not a .zip file.
/* Send Spreadsheet in an email as PDF, automatically */
function emailSpreadsheetAsPDF() {
// Send the PDF of the spreadsheet to this email address
const email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Árajánlat - EKOL Hungary').getRange('E3').getValue().toString();
// Get the currently active spreadsheet URL (link)
// Or use SpreadsheetApp.openByUrl("<>");
const ss = SpreadsheetApp.getActiveSpreadsheet();
// Subject of email message
const subject = `EKOL Hungary - ${ss.getName()}`;
// Email Body can be HTML too with your logo image - see ctrlq.org/html-mail
const body = "Ide majd kell valami szöveg";
// Base URL
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ss.getId());
const exportOptions =
'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=A4' + // 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
const token = ScriptApp.getOAuthToken();
const sheets = ss.getSheets();
// make an empty array to hold your fetched blobs
const blobs = [];
for (let i = 0; i < sheets.length; i += 1) {
// Convert individual worksheets to PDF
const response = UrlFetchApp.fetch(url + exportOptions + sheets[i].getSheetId(), {
headers: {
Authorization: `Bearer ${token}`
}
});
// convert the response to a blob and store in our array
blobs[i] = response.getBlob().setName(`${sheets[i].getName()}.pdf`);
}
// create new blob that is a zip file containing our blob array
const zipBlob = Utilities.zip(blobs).setName(`${ss.getName()}.zip`);
// Define the scope
Logger.log(`Storage Space used: ${DriveApp.getStorageUsed()}`);
// If allowed to send emails, send the email with the PDF attachment
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [zipBlob]
});
}
I have also tried it this way, but it sends a corrupted PDF.
function emailSpreadsheetAsPDF() {
const sheetToPrint = "Árajánlat - EKOL Hungary"; // name of the sheet to print
const ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1XTJF_-qYFvE4IVkA77YsOg3yfO_PX46z8z0_AtYg_Go/edit#gid=0");
const ssID = ss.getId();
const email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Árajánlat - EKOL Hungary').getRange('E3').getValue().toString();
const subject = `EKOL Hungary - ${ss.getName()}`;
const body = "Kicsit szépítettem rajta. Viszont, ide majd kéne valami szöveg. Mi legyen?";
const shID = ss.getSheetByName(sheetToPrint).getSheetId();
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ss.getId());
const exportOptions =
'&size=A4'+
'&portrait=true'+
'&fitw=true'+
'&sheetnames=false&printtitle=false'+
'&pagenumbers=false&gridlines=false'+
'&fzr=false'+
'&gid='+shID;
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [{
fileName: `EKOL Hungary - Árajánlat` + ".pdf",
content: response.getBytes(),
mimeType: "application/pdf"
}]
});
}
I would really appreciate any help you could give me as I am new to coding.
Instead of using UrlFetchApp, go for ss.getAs('application/pdf') (See here)
function emailSpreadsheetAsPDF() {
// Send the PDF of the spreadsheet to this email address
var email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Árajánlat - EKOL Hungary').getRange('E3').getValue().toString();
// Get the currently active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Subject of email message
const subject = `EKOL Hungary - ${ss.getName()}`;
// Get blob
var blob = ss.getAs('application/pdf');
// Send email
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [blob]
});
After several tries, the code below has done the trick.
// Generate a PDF file from a Google spreadsheet and send it to a specified email address
function emailSpreadsheetAsPDF() {
const sheetToPrint = "Árajánlat - EKOL Hungary"; // name of the sheet to print
const ss = SpreadsheetApp.getActiveSpreadsheet(); // the sheets to use
const email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Árajánlat - EKOL Hungary').getRange('E3').getValue().toString(); // grab the email address from the specified cell
const subject = `EKOL Hungary - ${ss.getName()}`; // the subject of the email
const body = "Kicsit szépítettem rajta. Viszont, ide majd kéne valami szöveg. Mi legyen?"; // body of the email
const shID = ss.getSheetByName(sheetToPrint).getSheetId(); // the ID of the sheet
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ss.getId()); // url of the spreadsheet
const exportOptions =
'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=A4'+ // size of the PDF (legal / A4 / letter)
'&portrait=true'+ // orientation of the PDF (false for landscape)
'&fitw=true'+ // 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='+shID; // the sheet's Id
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
// generate the PDF file
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
// send the email to the specified address with the specified body text and attached PDF file
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [{
fileName: `EKOL Hungary - ${ss.getName()}` + ".pdf",
content: response.getBytes(),
mimeType: "application/pdf"
}]
});
}
I have been trying to make a script that will send email of a range of cells over email. While the sending email part works perfectly, when i add time based trigger to it, its sending out a random email i dont understand.
I am trying to send out a range of cells in my sheet that gets updated live to my boss automatically at 9:30Am everyday.
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getDataRange();
var recipient = 'aaaabalamurali1996#gmail.com'
var subject = 'NRV Tracker'
var date = Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")
var schedRange = sheet.getRange("A1:Y6");
//var schedRange = sheet.getRange(Col == 3 && compare == date);
var body = '<div style="text-align:center;display: inline-block;font-family: arial,sans,sans-serif">'
body += '<H1>'+ 'NRV Tracker ' +'</H1>';
body += '<H2>'
body += getHtmlTable(schedRange);//change this line
body += '</div>';
debugger;
recipient = 'abc#abc.com'; // For debugging, send only to self
GmailApp.sendEmail(recipient, subject, "Requires HTML", {htmlBody:body})
var ts = ss.getSheetByName("D-1 Day");
var srange = sheet.getRange("A1:Y6");
var trange = ts.getRange("A1:Y6");
srange.copyTo(trange, {contentsOnly: true});
}
function getHtmlTable(range){
var ss = range.getSheet().getParent();
var sheet = range.getSheet();
startRow = range.getRow();
startCol = range.getColumn();
lastRow = range.getLastRow();
lastCol = range.getLastColumn();
// Read table contents
var data = range.getValues();
// Get css style attributes from range
var fontColors = range.getFontColors();
var backgrounds = range.getBackgrounds();
var fontFamilies = range.getFontFamilies();
var fontSizes = range.getFontSizes();
var fontLines = range.getFontLines();
var fontWeights = range.getFontWeights();
var horizontalAlignments = range.getHorizontalAlignments();
var verticalAlignments = range.getVerticalAlignments();
var colWidths = [];
for (var col=startCol; col<=lastCol; col++) {
colWidths.push(sheet.getColumnWidth(col));
}
var rowHeights = [];
for (var row=startRow; row<=lastRow; row++) {
rowHeights.push(sheet.getRowHeight(row));
}
var tableFormat = 'style="font-size: 10px; border:1px solid black;border-collapse:collapse;text-align:center" border = 1 cellpadding = 1';
var html = ['<table '+tableFormat+'>'];
// Column widths appear outside of table rows
for (col=0;col<colWidths.length;col++) {
html.push('<col width="'+colWidths[col]+'">')
}
for (row=0;row<data.length;row++) {
html.push('<tr height="'+rowHeights[row]+'">');
for (col=0;col<data[row].length;col++) {
// Get formatted data
var cellText = data[row][col];
if (cellText instanceof Date) {
cellText = Utilities.formatDate(
cellText,
ss.getSpreadsheetTimeZone(),
'M/d');
}
var style = 'style="'
+ 'color: ' + fontColors[row][col]+'; '
+ 'font-family: ' + fontFamilies[row][col]+'; '
+ 'font-size: ' + fontSizes[row][col]+'; '
+ 'font-weight: ' + fontWeights[row][col]+'; '
+ 'background-color: ' + backgrounds[row][col]+'; '
+ 'text-align: ' + horizontalAlignments[row][col]+'; '
+ 'vertical-align: ' + verticalAlignments[row][col]+'; '
+'"';
html.push('<td ' + style + '>'
+cellText
+'</td>');
}
html.push('</tr>');
}
html.push('</table>');
return html.join('');
}
When i use the trigger i am getting this email.
enter image description here
Try referencing the range of cells that you wish to send to a new sheet and use the code below to send that sheet as a PDF. It is very easy to implement.
// Generate a PDF file from a Google spreadsheet and send it to a specified email address
function emailSpreadsheetAsPDF() {
const sheetToPrint = "SPREADSHEET NAME"; // name of the sheet to print
const ss = SpreadsheetApp.getActiveSpreadsheet(); // the sheets to use
const email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SHEET NAME').getRange('E3').getValue().toString(); // grab the email address from the specified cell
const subject = `SUBJECT - ${ss.getName()}`; // the subject of the email
const body = "BODY"; // body of the email
const shID = ss.getSheetByName(sheetToPrint).getSheetId(); // the ID of the sheet
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ss.getId()); // url of the spreadsheet
const exportOptions =
'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=A4'+ // size of the PDF (legal / A4 / letter)
'&portrait=true'+ // orientation of the PDF (false for landscape)
'&fitw=true'+ // 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='+shID; // the sheet's Id
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
// generate the PDF file
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
// send the email to the specified address with the specified body text and attached PDF file
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [{
fileName: `FILE NAME - ${ss.getName()}` + ".pdf",
content: response.getBytes(),
mimeType: "application/pdf"
}]
});
}
All you have to do is change the SPREADSHEET NAME, SHEET NAME, SUBJECT, BODY, and FILE NAME. Changing around the ExportOptions could also potentially help you.
Once you have this implemented, just set up a trigger for it to run every morning at 9AM.
If you have any questions, do not hesitate to contact me.
I am trying to automate by a script the sending of a Sheet (active or not) of a workbook and only one sheet and not the whole workbook to a list of email addresses. Furthermore, I would like the Sheet to be converted to excel format when it is attached to the email.
Thank you for your answers
Try this:
function emailSpreadsheetAsPDF() {
const sheetToPrint = 'SPREADSHEET_NAME'; // name of the sheet to print
const ss = SpreadsheetApp.getSheetByName('SHEET_NAME'); // the sheets to use
const email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SHEET_NAME').getRange('RANGE').getValue().toString(); // grab the email address from the specified cell
const subject = `SUBJECT - ${ss.getName()}`; // the subject of the email
const body = "BODY"; // body of the email
const shID = ss.getSheetByName(sheetToPrint).getSheetId(); // the ID of the sheet
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ss.getId()); // url of the spreadsheet
const exportOptions =
'exportFormat=pdf&format=xlsx' + // export as pdf / csv / xls / xlsx
'&gid='+shID; // the sheet's Id
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
// generate the file
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
// send the email to the specified address with the specified body text and attached file
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [{
fileName: `EKOL Hungary - ${ss.getName()}` + ".xlsx",
content: response.getBytes(),
mimeType: "application/xlsx"
}]
});
}
Just substitute the SPREADSHEET_NAME, SHEET_NAME, RANGE, and BODY to what is true for your spreadsheet.
You can add a Trigger under the Triggers menu point (left side of the Script Editor) to automatically run the script whenever you want it to run.
Thanks but I failed to use it
But by combining several scripts, I found one that works:
function onSubmit(e){
Logger.log('submit ran');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//Send active sheet as email attachment
var ss = SpreadsheetApp.getActiveSpreadsheet()
var ssID = ss.getId();
var sheetgId = ss.getActiveSheet().getSheetId();
var sheetName = ss.getName();
var token = ScriptApp.getOAuthToken();
var email = "xxx#xx";
var subject = "xxxxx";
var body = "xxxxx";
var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export?" + "format=xlsx" + "&gid="+sheetgId+ "&portrait=false" + "&exportFormat=xlsx";
var result = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Bearer ' + token
}
});
var contents = result.getContent();
MailApp.sendEmail(email,subject ,body, {attachments:[{fileName:sheetName+".xlsx", content:contents, mimeType:"application//xlsx"}]});
};
Now what I would like is to be able to send the sheet to email addresses located on another sheet.
Also in "subject", I would like to combine "xxxx" + a date in a cell of the active sheet: "xxxx dd / mm / yyyy"
I haven't figured out how to do it yet !!!
I have a Form that when submitted will trigger a function to write the values of that submittal to the proper sheet in a Spreadsheet.
I then wish to email that adjusted sheet to someone.
I searched google api for help and could not resolve or reverse engineer the proper code
function sendpdf(){ // Function trigger is on form submit
var ss = SpreadsheetApp.getActiveSheet();
var sourceSheet = ss.getSheetName();
var workingRow = ss.getLastRow();
var dataRange = ss.getRange(workingRow, 1, 1, 4);
var data = dataRange.getValues();
var row = data[0]; // entire row
var col1 = row[0]; // first column timestamp A
var col2 = row[1]; // Client B
var col3 = row[2]; // Item C
var sass = SpreadsheetApp.getActiveSpreadsheet();
var targetSheet = sass.getSheetByName(col2);
targetSheet.insertRowBefore(4);
targetSheet.getRange("A4").setValue(col1);
targetSheet.getRange("B4").setValue(col2);
targetSheet.getRange("C4").setValue(col3);
MailApp.sendEmail(to:"reciever#email.com",subject:"See Attached PDF regarding" + col2,body:col2+" submitted a new request"
// , attach:targetSheet.pdf
// need the code to turn the targetSheet into a PDF and then email the PDF
)
}
The Spreadsheet contains 12 sheets and I expect the script to email the proper sheet that was just adjusted to someone any help would be appreciated
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var folderID = "FOLDERID"; // Folder id to save pdf in a folder.
var folder = DriveApp.getFolderById(folderID);
var newSpreadsheet = SpreadsheetApp.create(pdfName); // Name new Spreadsheet
var sheet = sourcesheet.copyTo(newSpreadsheet); //copy activesheet to new spreadsheet
newSpreadsheet.getSheetByName('Sheet1').activate(); //select "sheet1"
newSpreadsheet.deleteActiveSheet(); //delete "sheet1"
var newFile = folder.createFile(newSpreadsheet);
var pdf = DriveApp.getFileById(newSpreadsheet.getId());
var theBlob = pdf.getBlob().getAs('application/pdf').setName(pdfName); //create pdf
from new sheet in folder
var url, //create variable from url of the new sheet
sheets = newSpreadsheet.getSheets()
url = Drive.Files.get(newSpreadsheet.getId())
.exportLinks['application/pdf']; //create the pdf
url = url + '&size=a4' + //paper size
'&portrait=true' + //orientation, false for landscape
'&fitw=true' + //fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' + //hide optional
'&gridlines=false' + //false = hide gridlines, true = show
'&fzr=false'; //do not repeat row headers (frozen rows) on each page, true = show
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Bearer ' + token
}
});
DriveApp.getFilesByName(pdfName).next().setTrashed(true); //delete newSpreadsheet
var attachmentName = pdfName + '.pdf';
var optAdvancedArgs = {name: "NAMEFROM", htmlBody: htmlBody, replyTo : from,
from:from, attachments: [response.getBlob().setName(attachmentName)], }; //attach pdf
GmailApp.sendEmail(mailTo, subject, body, optAdvancedArgs); //send email with
advanced arguments
This should get you going ...
Good luck !
I am building a sheet that emails individuals PDF reports. I have this script working with a "hard coded" email address, however since each page of my google sheet needs to go to a different person. I am trying to figure out the language to make it look into the cell G3 of EACH SHEET and send the file to the respective email address.
IE sheet 1 emailed to address in G3 (dave#me.com)
Sheet 2 emailed to address in G3 (john#happy.com)
Thanks for your wisdom in advance. Here is what i have so far that WORKS, but it sends the individual files to me (arademacher#XXXX.com), then i must fwd to each person.
function ZIP_PDF_EMAIL_INDIVIDUAL() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Email subject and message body
var url = ss.getUrl();
url = url.replace(/edit$/,'');
var url_ext = 'export?exportFormat=pdf&format=pdf' // export as pdf
+ '&size=letter' // paper size
+ '&portrait=true' // orientation, false for landscape
+ '&fitw=true' // fit to width, false for actual size
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenumbers=false&gridlines=false' // hide pagenumbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&gid='; // the sheet's Id
var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();
for (var i=0; i<sheets.length; i++) {
var response = UrlFetchApp.fetch(url + url_ext + sheets[i].getSheetId(), {
headers: {
'Authorization': 'Bearer ' + token
}
});
var email = "arademacher#XXXX.com"
var message = "Monthly Report for " + ss.getName();
var subject = "PTO & Stipend Report - " + (new Date()).toString();
MailApp.sendEmail(email, subject, message, {attachments:[response]});
};
}
var email = sheets[i].getRange("G3").getValue();