Book Image

Google Apps Script for Beginners

By : Serge Gabet
Book Image

Google Apps Script for Beginners

By: Serge Gabet

Overview of this book

Table of Contents (16 chapters)
Google Apps Script for Beginners
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Using User Interfaces in Spreadsheets and Documents
Index

Creating e-mail messages


There are two Google services available to send e-mails: Gmail app and MailApp. The latter has only methods to send e-mails, while we have seen that Gmail app can do much more! When simply sending a message, we can use either of them interchangeably; I used to type MailApp more frequently but it is nothing more than a personal habit.

The basic process is really simple as described in the documentation (example taken from Google documentation page):

// Send an email with a file from Google Drive attached as a PDF.
 var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
 GmailApp.sendEmail('[email protected]', 'Attachment example', 'Please see the attached file.', {
     attachments: [file.getAs(MimeType.PDF)],
     name: 'Automatic Emailer Script'
 });

In the optional parameters, you can use some interesting values as follows: