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>`)

NitroGAS Chrome Extension

Want this snippet handy inside the Apps Script editor? NitroGAS gives you free themes and snippets — plus optional Co-Pilot when you want a boost (1-week, 1-month, or yearly passes — no subscription). Happy Coding!

Get the Extension