Send Emails with Attachments with Google Apps Script and Mandrill

Gmail sending limits are restricted especially when you are sending emails programatically as in the case of Mail Merge. You can only send a few hundred emails per day and then you’ve to wait the entire day for Google to reset your limit.

If you would like to send thousands of emails but without the daily restrictions, you can consider using an email sending service like Mandrill. You need a web domain and need to verify the ownership of that domain with Mandrill so that you are allowed to send emails via Mandrill. Once verified, you get an API key from Mandrill that you can use with Apps Script to send emails in bulk without restrictions.

Here’s a sample snippet that sends emails from Google Scripts via Mandrill. You also have to option to include file attachments in your emails and these files can be placed in a Google Drive folder. The sendEmail() method accepts both plain text and HTML Mail.

function sendEmail() {
  var MANDRILL_API_KEY = "<>";
  var files = [

  var recipients = [
      "email": "",
      "name": "Amit Agarwal",
      "type": "to"
    }, {
      "email": "",
      "type": "cc"
    }, {
      "email": "",
      "type": "bcc"
  var attachments = [];
  for (var f in files) {
    var file = DriveApp.getFileById(files[f]);
      "type": file.getMimeType(),
      "name": file.getName(),
      "content": Utilities.base64Encode(file.getBlob().getBytes())
  var params = {
    "key": MANDRILL_API_KEY,
    "message": {
      "from_email": "<>",
      "from_name": "<>",
      "to": recipients,
      "attachments": attachments,
      "headers": {
        "Reply-To": ""
      "subject": "Enter email subject",
      "text"   : "Enter email body in plain text",
      "html"   : "Enter HTML content with tags"

  var response = UrlFetchApp.fetch(
    "", {
      'method': 'POST',
      'payload': JSON.stringify(params),
      'contentType': 'application/json'


It may take some time to build your mail domain reputation and hence the emails are queued and not sent instantly. Go to Mandrill Dashboard – Outbound Emails – Activity to see the current status of your sent Emails.

Mandrill Email Open Report

Also, it is no longer possible to send emails from generic addresses like or since Mandrill requires domain ownership verification to reduce spam emails.