Thursday, March 4, 2021
Home Blogging Send Emails with Attachments with Google Apps Script and Mandrill

Send Emails with Attachments with Google Apps Script and Mandrill

Gmail sending limits are confined particularly when you are sending messages programmatically as on account of Mail Merge. You can just send two or three hundred messages for each day and afterward you’ve to trust that Google will reset your cutoff.

On the off chance that you might want to send a great many messages yet without the every day limitations, you can consider utilizing an email sending administration like Mandrill. You need a web space and need to confirm the responsibility for area with Mandrill so you are permitted to send messages by means of Mandrill. When confirmed, you get an API key from Mandrill that you can use with Apps Script to send messages in mass without limitations.

Here’s an example bit that sends messages from Google Scripts by means of Mandrill. You likewise need to alternative to incorporate document connections in your messages and these records can be put in a Google Drive organizer. The sendEmail() technique acknowledges both plain content and HTML Mail.

function sendEmail() {

  var MANDRILL_API_KEY = "<<your key here>>";

  var files = [
    "<<Google Drive File ID 1>>",
    "<<Google Drive File ID 2>>",
    "<<Google Drive File ID 3>>"
  ];

  var recipients = [
    {
      "email": "ctrlq+to@labnol.org",
      "name": "Amit Agarwal",
      "type": "to"
    }, {
      "email": "ctrlq+cc@labnol.org",
      "type": "cc"
    }, {
      "email": "ctrlq+bcc@gmail.com",
      "type": "bcc"
    }
  ];

  var attachments = [];

  for (var f in files) {
    var file = DriveApp.getFileById(files[f]);
    attachments.push({
      "type": file.getMimeType(),
      "name": file.getName(),
      "content": Utilities.base64Encode(file.getBlob().getBytes())
    });
  }

  var params = {
    "key": MANDRILL_API_KEY,
    "message": {
      "from_email": "<<Sender's Email Address>>",
      "from_name": "<<Sender Name>>",
      "to": recipients,
      "attachments": attachments,
      "headers": {
        "Reply-To": "reply@example.com"
      },
      "subject": "Enter email subject",
      "text"   : "Enter email body in plain text",
      "html"   : "Enter HTML content with <b>tags</b>"
    }
  };

  var response = UrlFetchApp.fetch(
    "https://mandrillapp.com/api/1.0/messages/send.json", {
      'method': 'POST',
      'payload': JSON.stringify(params),
      'contentType': 'application/json'
    });

  Logger.log(response.getContentText());
}

It might require some investment to construct your mail space notoriety and thus the messages are lined and not sent immediately. Go to Mandrill Dashboard – Outbound Emails – Activity to see the current status of your sent Emails.

Send Emails with Attachments with Google Apps Script and Mandrill

Additionally, it is not, at this point conceivable to send messages from nonexclusive tends to like @gmail.com or @outlook.com since Mandrill requires space possession confirmation to decrease spam messages.

namanmahajanhttp://artistogram.in
I am a Multimedia artist, I am born and based on Dewas (M.P), I am working as a freelancer with various brands and different country. My expertise are Graphics designing, motion graphics, 2d/3d animation, advertising videos, cartoons designing, all types of packaging and branding designing, digital marketing, SEO, design website and app Developments etc...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular