Page tree

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.


FeatureConsumer
(e.g., gmail.com)
G Suite free edition (legacy)G Suite
Basic / Gov
G Suite Business / Enterprise / Education
Email recipients per day100 / day100 / day1,500 / day1,500 / day
Email read/write (excluding send)20,000 / day40,000 / day50,000 / day50,000 / day
Email attachments250 / msg250 / msg250 / msg250 / msg
Email body size200kB / msg200kB / msg400kB / msg400kB / msg
Email recipients per message50 / msg50 / msg50 / msg50 / msg
Email total attachments size25MB / msg25MB / msg25MB / msg25MB / msg




The best way to get IT support is to use the new Service One Platform.