How To Create A Simple Mail Merge Script With Google Apps Script

Written by frenchcooc | Published 2021/05/03
Tech Story Tags: mail-merge | google-apps-script | email-marketing | email | gmail | javascript | mailmeteor | marketing

TLDR The 6 steps to reproduce to create your Google script to send emails in bulk with Gmail. All your recipients receive a unique email sent from your email address. Be sure to abide by Gmail bulk senders guidelines. Use Gmail to send a reasonable amount of emails per day. If you have a @gmail.com email address, you can send at most 500 emails/day while with a Google Workspace account, you are limited to about 2000 emails a day. The first time you use the script it will ask for permission to send email on your behalf.via the TL;DR App

Sending mass emails from Gmail is sometimes seen as a challenge. I
can tell you it's not! In this article we'll look at the basics of
building a mail merge script for Gmail and how it can fit your email
marketing needs.
First, here's what you need to send emails in bulk with Gmail:
  • Gmail (or Google Workspace) account
  • a list of contacts
  • a template of the emails you want to send
  • basic development skills
Now let's see the 6 steps to reproduce to create your Google script to send emails.

Tutorial: Building a mail merge script for Gmail

Step 1. Open Google Apps Script
Step 2. Click on the "New project" button to create a new project. You should now see the script editor.
Step 3. From the Google Apps Script editor, copy and paste the following script:
function sendEmails() {
  const recipients = ["[email protected]", "[email protected]"];

  const template = {
    "subject": "My mail merge script for Gmail",
    "content": `Hi,<br><br>
    
    I just wanted to show you how to send emails in bulk with my Gmail account!<br><br>
    
    Take care,<br>
    - Corentin<br><br>
    
    PS: <a href="https://mailmeteor.com/mail-merge-gmail/script">Click here to do it by yourself</a>`
  }

  recipients.forEach(function (recipient) {
    MailApp.sendEmail({
      to: recipient,
      subject: template.subject,
      htmlBody: template.content
    })
  })
}
Update the
recipients
variable with your list of recipients. Also update the
template
variable with your subject and content to make it fit your needs.
Step 4. Click on "Save" to save your changes
Step 5. Then click on "▶️ Run" to send your emails.
Note: the first time you use the script it will ask for the permission to send emails on your behalf. Then it won't ask you again.
Emails are usually immediately delivered, but sometimes it takes a few seconds. Check your "Sent" folder in Gmail to confirm that all emails have been sent! As you will see, all your recipients receive a unique email sent from your email address. You don't need to use bcc or any other techniques.

Conclusion

Some say that it's impossible to send emails in bulk with Gmail. They can't be more untrue. Of course, this is a very basic macro for Google Sheets to send lots of emails with Gmail. You might need to adapt it a little bit more, but thanks to Google Apps Script you can do lot of things.
Before you go, here are two things to keep in mind when using Gmail as an email marketing tool:
  1. Be sure to abide by Gmail bulk senders guidelines. Especially, note that you are limited to send a reasonable amount of emails per day. If you have a @gmail.com email address, you can send at most 500 emails/day while with a Google Workspace account, you sending limit hits 2000 emails per day. That's probably well enough for 99% of Gmail users, but it's good to have in mind those limits.
  2. If you are looking for more a advanced script, for example that let you send personalized emails (e.g. Hi
    {{ firstname }}
    ), I'd recommend you to use a Gmail mail merge tool such a Mailmeteor that does it for you. It already handles personalization, as well as dozens of features from attachments to aliases. Learn more about the features and benefits of Mailmeteor here.
This article is part of an extended guide on Mail merge in Gmail (2021). If you want to learn much more, go check it out!

Written by frenchcooc | CTO & Co-founder - Mailmeteor.com
Published by HackerNoon on 2021/05/03