Skip to content

Instantly share code, notes, and snippets.

  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Send emails with attachment from a Google Sheet using Google Apps Script. Read full article here:
function onOpen()
var ui = SpreadsheetApp.getUi();
.addItem('send PDF Form', 'sendPDFForm')
.addItem('send to all', 'sendFormToAll')
function sendPDFForm()
var row = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
function sendEmailWithAttachment(row)
var filename= 'fillable-form-5516.pdf';
var file = DriveApp.getFilesByName(filename);
if (!file.hasNext())
console.error("Could not open file "+filename);
var client = getClientInfo(row);
var template = HtmlService
template.client = client;
var message = template.evaluate().getContent();
subject: "The form to fill",
htmlBody: message,
attachments: []
function getClientInfo(row)
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var values = sheet.getRange(row,1,row,3).getValues();
var rec = values[0];
var client =
first_name: rec[0],
last_name: rec[1],
email: rec[2]
}; = client.first_name+' '+client.last_name;
return client;
function sendFormToAll()
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var last_row = sheet.getDataRange().getLastRow();
for(var row=2; row <= last_row; row++)
sheet.getRange(row,4).setValue("email sent");
Copy link

I have an excel sheet that has print area that i would like to send as an attachment. Any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment