Sending Emails Using Apps Script


The built-in libraries in Google Apps Script makes sending emails extremely easy. By default, you have two libraries to choose from:

  1. MailApp
  2. GmailApp

They'll both work just fine if your goal is just to send an email. The GmailApp library will give you access to the user's inbox, which makes it a bit more useful for inbox automation.


To use MailApp for sending emails, you'd do something like this:

MailApp.sendEmail(recipient, subject, emailBody)

And for the GmailApp, it's basically the same:

GmailApp.sendEmail(recipient, subject, emailbody)

Now, things get interesting when you want to send HTML in your email. To do that, you just need to add in a fourth parameter as an object that includes a key for "htmlBody" and set it to an email body you created in HTML - so something like this:

function sendEmail(recipient, subject, emailBody) { GmailApp.sendEmail(recipient, subject, emailbody) } // Example Usage // sendEmail('email@example.com', 'Awesome Subject', `<p>Send this <strong>awesome</strong> email</p>`)
thumbnail

NitroGAS Chrome Extension

Want to reference this code snippet right from your Google Apps Script Project? Check out our NitroGAS Chrome Extension. This tool will help you build your scripts faster than you could imagine. The tool itself and access to the code snippets are 100% FREE - Happy Coding!

Get the Extension