"Mail Merge for Batch Email" is a project built on a Google Sheets file with Google Apps Script behind to generate and send emails to a group of people based on a template. It works similar to the mail merge function in major document editors. The first version came in 2017, and there have been newer versions with more functions, such as rich-text content, file attachment, multiple templates, inline images and QR codes, etc.
Mail Merge for Batch Email (v9.0) (Google Sheets, click to make a copy)
Release date: 2025-04-04
First release on GitHub at: https://github.com/charlotte-lau-hk/MailMergeForBatchEmail
Added "Preview Merged Emails" Feature: Users can now preview emails before sending, with a user-friendly interface that includes navigation to review each recipient’s email, ensuring accuracy and confidence in the batch email process.
Enhanced UI for Menu and Folder Picker: The custom menu now includes emoji icons for better visual clarity, and the Folder Picker has been redesigned with a tree-like hierarchy using ideographic spaces, improving readability and navigation of folder structures.
Improved Auto-Rerun Mechanism: The auto-rerun feature has been upgraded to set a trigger that resumes execution after a 6-minute timeout (applicable to all users), ensuring reliable completion of large email batches.
Introduced "Initialize Sheets" Feature: A new menu option allows users to set up all required worksheets (Dashboard, Datasheet, Settings, Template1, Usage) with default content and sample data, simplifying the initial setup process.
Keeping all features from previous version: Rich-text using MarkDown. File Attachment in Sub-folders. Inline Images and QR Codes. Multiple Templates, etc.
The older version is still available: Mail Merge for Batch Email (v8.13) (Google Sheets)
Updated 2024-04-23 (Bug fix: QR generation)
On the worksheet "DataSheet", prepare the data for mail merge:
Column "To Send": Enter "Yes" or "Y" for the records to process.
Column "Done": Indicate whether a record has been processed. (must clear it to send again)
Column "Email Address": Store the email address for each record. You may enter multiple email addresses OK; should be comma-separated.
Column "Attachment List": A comma separated list of the names of the files to send. File name is case-sensitive. All files must be saved in the same folder. Refer to "Folder ID" below.
Column "SubFolder" (*NEW in v7.00): The subfolder name under the attachment folder. Must be a direct child. If no subfoler is given, the attachment folder will be used.
Column "Template Name": Name of the worksheet of the template to use.
Name of the column for inline image from a link, must start with "imglink", e.g. "imglink1", "imglink2", etc. Optional field data should be URL.(Note: This will embed the image in the email. If you want to use external image source, please use HTML code instead.)
Name of the column for inline image from a file in the attachment folder, must start with "imgfile", e.g. "imgfile1", "imgfile2", etc. Optional field data should be the filename of the image file in the attachment folder.
Name of the column for a QR code, must start with "qrdata", e.g. "qrdata1", "qrdata2", etc.. Optional field data should be the data for the QR code (text or URL).(Note: Google Chart API is used, and so it may fail to generate QR code if the Google Chart API is unavailable)
WARNING: The images are embedded in the email, so don't include a large image! To include a linked external image, write HTML code directly (accepted by MarkDown).
On the worksheet "Settings"
Data "Cc" and "Bcc": Add Cc and Bcc to each email. Can be comma-separated list.
Data "Folder ID":
Fill in the ID of the folder in Google Drive storing files for attachment; OR,
Click menu “Mail Merge for Batch Email” -> “Pick Folder for Attachment” to choose the folder.
Important: Leave this field blank for no attachment or the script will stop if the ID is invalid.
Data "Send as" can change the name (not email address) of the sender.
On the worksheet "Template1"
Note: "Template1" is the name of the default template. Don't change this name or else the script may fail to work.
Prepare the templates of mail subject and body.
Mail body now uses markdown syntax for rich-text formatting (See below for more information). You can also use HTML tags.
Use the syntax ${"fieldName"} for a merge field.
Create a new template by duplicating this template.
Click menu “Mail Merge for Batch Email” -> “Send Emails Now!”.
Click menu “Mail Merge for Batch Email” -> “Check Mail Quota” to check remaining daily quota.
You will receive a log by email after execution.
Markdown syntax
*italic*
**bold**
__underline__
ordered list: 1.
unordered list: * - +
line break: (two spaces at end of line)
You can also add HTML code directly.
Reference:
Library used:
Since version 6.x: Showdown v2.1.0 at https://github.com/showdownjs/showdown
Older version: Showdown variant markdown-to-doc at https://github.com/anshulguleria/markdown-to-doc
Markdown Cheatsheet: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
Online Markdown Editor: https://jbt.github.io/markdown-editor/
This example is a derived work of "Simple Mail Merge", "Markdown to document converter" and "Showdown" at:
Limit:
Google account (Personal): 100 mail/day, 250 attachments/mail, 25 MB/mail
G Suite for Education: 1500 mail/day, 250 attachments/mail, 25 MB/mail
Ref: https://developers.google.com/apps-script/guides/services/quotas
There will be random delay for sending emails, and the emails may not arrive in order.