Area94
Area94

Reputation: 23

Gmail API with Attachments

How can I send an email message from Apps Script using the Gmail API that picks up a file from the Drive and includes in the message as an attachment.

I've looked in the official documentation but could not get this to work.

Upvotes: 1

Views: 660

Answers (1)

Mogsdad
Mogsdad

Reputation: 45710

You can accomplish this without using the GMail API, using the GmailApp Service instead. In fact, your use case is the example provided in the documentation for GmailApp.sendEmail().

 // 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'
 });

Upvotes: 2

Related Questions