The built-in libraries in Google Apps Script makes sending emails extremely easy. By default, you have two libraries to choose from:
- MailApp
- 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>`)
