November 06, 2013

Sending email with pdf as attachment in google spreadsheet

How to create an automatic email with attachment sending code in google spreadsheet

 This is a small

Google script code

that send mail periodically (by setting timer) by having an attached pdf copy to a sender mail.
Thanks to +bithesh soubhagya

 function myFunction() {
// convert spread sheet to portable document format (pdf) with google spreadsheet
     var sheetToPdf = SpreadsheetApp.openByUrl("");
     Logger.log(" sheet name :::: "+SpreadsheetApp.getActiveSheet().getName());
     MailApp.sendEmail('', 'Testing automatic email with google spreadsheet ', 'Hi, this is subject automatic email sender in google spreadsheet script running', {
     name: 'Google , Spreadsheet ',
     attachments: sheetToPdf
     Logger.log(" Email sent successfully !!! ");

Here is a small google script (.gs) function. the above code will sent the google spreadsheet as pdf document through mail. you can specify receivers mail id, subject etc in MailApp.sendEmail function.

Then, if you want to invoke the function automatically use timer button.

Sending alert while opening a file using  google script

function sentOnOpen() {
  var sheetToPdf = SpreadsheetApp.openByUrl("");
   var todayDate = new Date();
   Logger.log(" inside date "+todayDate);
   var htmlBody = sheetToPdf.getViewers()+" opened the Report on "+todayDate;
   var subject = " Report " ;
   var optAdvancedArgs = {name: "VIPIN", htmlBody: htmlBody};
   MailApp.sendEmail("belazy1987atgmaildotcom", subject , "Email Body" , optAdvancedArgs);
   Logger.log(" Sending email ");

you can set the timer. The timer option available on the script page. run it.

The full source code available here, you can run the script and check the result
click here to run the script

Facebook comments