Sending Email in Apps Script
Class MailApp used to Send email.
This service allows users to send emails with complete control over the content of the email.
Unlike GmailApp, MailApp's sole purpose is sending email.
MailApp cannot access a user's Gmail inbox.
Changes to scripts written using GmailApp are more likely to trigger a re-authorization request from a user than MailApp scripts.
We can use four different methods of MailApp class to send an email
- sendEmail(message)
- sendEmail(recipient, subject, body)
sendEmail(recipient, subject, body, options)
sendEmail(to, replyTo, subject, body)
Example Code snippet:
Sending an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
function sendEmailNotification() { var file = DriveApp.getFileById('Insert file id'); var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html'); MailApp.sendEmail('abc@example.com', 'Attachment example', 'Two files are attached.', { name: 'Automatic Email Script', attachments: [file.getAs(MimeType.PDF), blob] });
Limitations:
Quotas are set at different levels for users of consumer accounts (such as gmail.com) and G Suite free edition (discontinued), or different G Suite editions. Daily quotas are refreshed at the end of a 24-hour window; the exact time of this refresh, however, varies between users.
| Feature | Consumer (e.g., gmail.com) | G Suite free edition (legacy) | G Suite Basic / Gov | G Suite Business / Enterprise / Education |
|---|---|---|---|---|
| Email recipients per day | 100 / day | 100 / day | 1,500 / day | 1,500 / day |
| Email read/write (excluding send) | 20,000 / day | 40,000 / day | 50,000 / day | 50,000 / day |
| Email attachments | 250 / msg | 250 / msg | 250 / msg | 250 / msg |
| Email body size | 200kB / msg | 200kB / msg | 400kB / msg | 400kB / msg |
| Email recipients per message | 50 / msg | 50 / msg | 50 / msg | 50 / msg |
| Email total attachments size | 25MB / msg | 25MB / msg | 25MB / msg | 25MB / msg |
The best way to get IT support is to use the new
Service One Platform.