Mail Merge With Gmail: A Beginner’s Guide

On January 30, 2025
11min read
Veljko Ristić Content Manager @ Mailtrap
This is a symbolic graphic representation of mail merge with Gmail for an article that covers the topic in detail

Yeah, mail merge is the way to personalize your emails without breaking a sweat. 

Okay, I’m exaggerating a bit; some coding and prep work could be involved. But overall, it’s well worth the effort since it’s one of the few proven methods to boost your open and click-through rates. 

In this tutorial, I’ll show you how to use mail merge Gmail, covering the following:

Note: I included ready-made scripts and set-up flows. 

What is mail merge Gmail?

Mail merge is a technique for sending personalized emails to multiple recipients by dynamically inserting individual details (like names or unique links) into a single email template. It also helps partially automate the email personalization process. 

Gmail makes mail merge particularly accessible by leveraging Google Workspace (formerly G suite) tools like Google Sheets and add-ons such as YAMM. Or you can do it natively from the email client. Hit the links to jump to the methods. 

Now, I’d like to briefly cover typical usage scenarios and the benefits of using Gmail mail merge. 

The benefits 

  • Simplicity: Gmail’s intuitive interface and integration with Google Workspace tools make mail merge easy, even for non-technical users. You can do everything from Chrome, actually. 
  • Scalability: Gmail’s ability to handle relatively large email volumes (within its quota) ensures you can reach broader audiences effectively.
  • Integration: Google Sheets and Google App Script enable full customization, while YAMM offers a streamlined, analytics-driven experience.

Example scenarios

  • Newsletters: Deliver engaging updates tailored to recipient names or preferences.
  • Personalized outreach: Boost response rates by addressing recipients by name and including relevant details.
  • Event invites: Send customized invitations with event details like date, time, and location unique to each recipient.

Mail merge from Gmail email client 

Recently, Gmail has allowed mail to be merged directly from the web client. This feature replaces what used to be “multi-send,” and it’s located in the upper right corner of the “Compose” window. 

Gmail compose new email mail merge icon

Gmail supports merge tags starting with the @ + tag function (e.g., @lastname, @fullname, @email, etc.). The recipients cannot see who else got the message, and any replies you receive show up in a new thread. 

More importantly, Gmaill allows you to connect to a spreadsheet with recipient info, and you can use any of the sheet’s columns as merge variables. You can also use Google Contacts to select recipients, and the tool now allows for basic segmentation with Labels. Plus, you can upload a CSV to Contacts. 

As indicated earlier, mail merge Gmail is exclusive to Google Workspace for the following plans: 

  • Education Standard
  • Education Plus
  • Business Standard
  • Business Plus 
  • Enterprise Standard
  • Enterprise Plus
  • Workspace Individual

How to add recipients and use mail merge directly from the email client

  1. Launch Gmail, hit Compose, or open an existing draft email. 
  1. Click the mail merge icon next to the “To” line. The Compose window turns light purple to confirm you’re in mail merge mode. 
Gmail compose email window with mail merge enabled
  1. Within the message, type @ and select from the available tags, then hit Enter to confirm. 
Gmail mail merge adding merge tags
  1. There’s no option for automatic email tests, so it’s best to send to a few recipients first, then to the entire list.  

Tips:

  • To add recipients from a spreadsheet, first, upload the spreadsheet to your Drive. Then select “Add from a spreadsheet” under the “Mail Merge” option, select the spreadsheet, and hit “Insert”. Before clicking “Finish,” select the spreadsheet columns that feature recipients’ info.  
  • It’s possible to identify columns by using their position (e.g. @B for the second column). This is useful if your columns contain special characters. 
  • Gmail mail merge considers email addresses with special characters as invalid. 
  • Gmail automatically adds the Unsubscribe link to mail merge emails. If you choose this method, I suggest keeping the link as is. 

Now, if you need more customization options and basic automation, it’s best to opt for the App Script and Google Spreadsheet combo. Check the micro tutorial below ⬇️

Mail merge in Gmail using Google Spreadsheet and Google App Script

Using Google App Script for mail merge helps send personalized bulk emails from Gmail using data stored in Google Sheets. This method offers maximum customization, allowing you to tailor every aspect of your emails – from dynamic subject lines and personalized content to attaching specific files for each recipient.

That sounds great, but note that this requires at least basic coding skills. Here are the steps to set it all up. 

The code and tables below are fully customizable to your needs but keep in mind that any changes you make to the table need to be reflected in the code.

Step 1: Google spreadsheet setup

  1. Create a new spreadsheet specifically for email campaigns and name it descriptively, something like Mail Merge Campaign XY Data
  1. Set up the sheet columns and, in the first row, create headers for the data you will use in your email template. For example:
    • ‘Email’ (recipient’s email address)
    • ‘FirstName’
    • ‘LastName’
    • ‘Subject’
    • ‘CustomMessage’

Exemplary spreadsheet

EmailFirstNameLastNameSubjectCustomMessage
john.doe@example.comJohnDoeSpecial Offer for YouEnjoy a 20% discount!
jane.smith@example.comJaneSmithInvitation Just for YouJoin us at our event!

Neat trick: Most CRMs allow you to export contacts and contact details into a CSV, which you can upload to Sheets and adapt to your campaigns. The same goes for Google Contacts. 

  1. Click Extensions within the sheet you just created, then select Apps Script. Delete any placeholder code and paste the following script. 
function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // Starting row (excluding headers)
  var numRows = sheet.getLastRow() - 1; // Number of rows to process
  var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
  var data = dataRange.getValues();

  data.forEach(function(row) {
    var emailAddress = row[0]; // Column A
    var firstName = row[1];    // Column B
    var lastName = row[2];     // Column C
    var subject = row[3];      // Column D
    var customMessage = row[4]; // Column E

    if (emailAddress) {
      // Create the email body with personalization
      var message = 'Dear ' + firstName + ',\n\n' + customMessage + '\n\nBest regards,\nYour Company';

      // Send the email
      MailApp.sendEmail({
        to: emailAddress,
        subject: subject,
        body: message
      });

      Logger.log('Email sent to: ' + emailAddress);
    }
  });
}

Step 2: Running and testing the script 

  1. Before testing, you need to authorize the script; otherwise, it won’t work. Save it, then click the Run button and follow the authorization wizard to grant the script necessary permissions. 
  1. To test the functionality, run the script with a smaller set of test data to verify email sending and merge fields are performing as expected. You can do that by modifying the script range (rows). Here’s an example:
var numRows = 1; // Only process the first row for testing
  1. Once you run a successful test, process all rows in the range. 

Side notes: 

  • There’s no Cc or BCC, the method sends to all recipients from a specific sheet. 
  • There’s an option to set up mail merge from Google Docs and use Docs API, but that’s a topic for a different tutorial. 

Mail merge with attachments

Adding attachments to a mail merge in Gmail using Google App Script allows you to send personalized files along with your email content. 

This can be useful for sending individual reports, invoices, or other documents tailored to each recipient. However, I’d advise against using attachments for email marketing and mass emails since they may affect deliverability.

Step 1: Extend the spreadsheet with an attachment column

Add a new column to your spreadsheet for AttachmentID. This column will store the unique file IDs of the attachments stored in Google Drive.

Here’s the extended spreadsheet.

EmailFirstNameLastNameSubjectCustomMessageAttachmentID
john.doe@example.comJohnDoeSpecial Offer for YouEnjoy a 20% discount!1AbcD2EfG3HiJ4K
jane.smith@example.comJaneSmithInvitation Just for YouJoin us at our event!5LmN6OpQ7RsT8Uv

Step 2: Update the script to include attachments

Modify the script to include logic for fetching attachments from Google Drive. Here’s the code. 

function sendEmailsWithAttachments() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // Starting row (excluding headers)
  var numRows = sheet.getLastRow() - 1; // Number of rows to process
  var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
  var data = dataRange.getValues();

  data.forEach(function(row) {
    var emailAddress = row[0]; // Column A
    var firstName = row[1];    // Column B
    var lastName = row[2];     // Column C
    var subject = row[3];      // Column D
    var customMessage = row[4]; // Column E
    var attachmentId = row[5]; // Column F

    if (emailAddress) {
      // Create the email body with personalization
      var message = 'Dear ' + firstName + ',\n\n' + customMessage + '\n\nBest regards,\nYour Company';

      // Prepare attachments array
      var attachments = [];
      if (attachmentId) {
        try {
          var file = DriveApp.getFileById(attachmentId);
          attachments.push(file.getAs(file.getMimeType()));
        } catch (e) {
          Logger.log('Error fetching attachment for ' + emailAddress + ': ' + e.message);
        }
      }

      // Send the email
      MailApp.sendEmail({
        to: emailAddress,
        subject: subject,
        body: message,
        attachments: attachments
      });

      Logger.log('Email sent to: ' + emailAddress);
    }
  });
}

Quick breakdown

  • The script fetches the file from Google Drive using attachmentId.
  • It adds the file to the attachments array, automatically handling different file types.
  • The script handles any file type using file.getAs(file.getMimeType()).
  • It monitors the script’s progress with the Logger.log() statement. You can check the logs by clicking “Execution Log” in the App Script editor. 

How to get the attachment ID

  1. Locate the file in Google Drive. 
  2. Right-click the file and select ‘Get link’.
  3. Ensure the link access permission is set to Restricted
  4. Copy the file ID from the URL. It’s the part between /d/ and /view.

Example:

https://drive.google.com/file/d/1AbcD2EfG3HiJ4K/view?usp=sharing

The file ID in this example is 1AbcD2EfG3HiJ4K.

Step 3: Running and testing the script

The testing and deployment logic is the same as previously described, so I won’t detail the steps. As a reminder, you authorize the script, run it to a limited number of recipients, and then deploy it to all the recipients (the entire spreadsheet). 

Bonus tips: Error handling, quotas, scheduling, etc. 

  • Include a try-catch block when fetching attachments. This logs the errors without stopping the script. 
  • Free Gmail accounts have a daily limit of 500 emails, but note that they aren’t eligible for mail merge from the email client. You need App Scripts or add-ons. Google Workspace accounts are much higher eta. 2000 emails per day. However, mail merge may affect the limitations, so check the official Workspace docs
  • You can automate mail merge and schedule emails by setting up an App Scrip trigger. Within the editor, click the clock icon and create a new trigger. Then, configure the trigger to run sendEmails at a desired time. 
  • For a bit more advanced customization, you can add an HTML draft email using the htmlBody parameter in the MailApp.sendEmail

Tip: It’s possible to merge Gmail mail with Microsoft Excel tables. But I strongly advise against it since the method is unreliable, and you may encounter formatting issues. 

Mail merge in Gmail using Google Spreadsheet and YAMM

Yet Another Mail Merge (YAMM) is a Google Sheets add-on with simplified mail merge features, making it accessible for both technical and non-technical users. It allows you to personalize emails, send bulk and follow-up messages, and track analytics – all through an intuitive interface. 

Unlike Google App Script, YAMM doesn’t require coding and has more straightforward formatting. Plus, there’s much less work to track email performance; you don’t have to temper with links and Google Analytics. 

Here are the steps to set it all up. 

Step 1: Install YAMM as a Google Sheets add-on

  1. In the Google Sheets menu bar, select ‘Extensions,’ then ‘Add-ons,’ and click ‘Get add-ons’. 
YAMM addon under Google Extensions
  1. Search for “Yet Another Mail Merge,” hit Install, and follow the wizard to grant the add-on permissions. 

Note: YAMM is a paid add-on, but they offer a free account with certain limitations. The pricing is really fair: $3 or $5 per month at the time of writing. 

Step 2: Set up Google spreadsheet for mail merge

The setup is the same as previously described. You need a sheet featuring column names specific to the emails and the recipients you’re targeting. Here’s the exemplary sheet again. 

EmailFirstNameLastNameSubjectCustomMessage
john.doe@example.comJohnDoeSpecial Offer for YouEnjoy a 20% discount!
jane.smith@example.comJaneSmithInvitation Just for YouJoin us at our event!

Step 3: Use the YAMM interface to set up the mail merge

  1. Within the spreadsheet, go back to Extensions, select YAMM, and click Start Mail Merge. 
  1. The action above opens a sidebar, and here’s how to use it. 
    • Sender Email: Choose the Gmail account you’d like to use to send the emails.
    • Email Template: Select an existing Gmail draft to use as a template. If you don’t have one, compose the draft in Gmail with placeholders that match the spreadsheet headers (e.g. {{FirstName}}). 
    • Spreadsheet Data: YAMM automatically detects the personalization columns in the spreadsheet. 
  1. Map the spreadsheet columns to email template placeholders. Here’s a simple example with merge tags:
Subject: {{Subject}}

Hi {{FirstName}},

{{CustomMessage}}

Looking forward to your response!

Best regards, 
[Your Name]

Important Notes

  • The[Your Name]variable in the example above isn’t tied to mail merge. You need to add your business name or the email signature you’re using. 
  • If you use mail merge tools for marketing campaigns, don’t forget to include an unsubscribe link. 

Step 4: Testing, sending emails, and YAMM analytics

  1. Navigate to the YAMM sidebar and click the “Send test email” button. Then, go to your inbox and check if the email looks and performs as expected. 
  1. If the test goes well, click “Send Emails” in the sidebar, and YAMM will begin sending emails one by one. 
  1. Finally, you can review the metrics in the YAMM dashboard; the analytics you get include:
    • Open rates
    • Click-through rates
    • Bounces

Important Note: Even though you’re using YAMM, Google’s sending limits still apply. 

Mail merge with attachments

YAMM supports mail merge attachments, including files like PDFs, images, or other documents. It only attaches a file via URL, not its unique ID.  

Step 1: Extend the sheet to add attachments 

Add the AttachmentURL column to the spreadsheet to store the links to files you’d attach to each email. 

EmailFirstNameLastNameSubjectCustomMessageAttachmentURL
john.doe@example.comJohnDoeSpecial Offer for YouEnjoy a 20% discount!https://drive.google.com/file/d/1AbcD2EfG3HiJ4K
jane.smith@example.comJaneSmithInvitation Just for YouJoin us at our event!https://drive.google.com/file/d/5LmN6OpQ7RsT8Uv

Step 2: Prepare the attachments in Google Drive

I assume the files are already on your drive. If not, upload them first. Then, get a shareable link for each and ensure access is granted only to the users specific to each file. 

Finally, copy-paste each link to the corresponding row under the AttachmentURL column.

Step 3: Configure YAMM to handle attachments

Start YAMM by clicking Extensions, then Yet Another Mail Merge, then Start Mail Merge. 

Step 4: Reconfigure the YAMM sidebar to accept attachments

Map the AttachmentURL column in the spreadsheet to the attachments field in YAMM. The add-on fetches the files from the given URLs.

Step 5: Test and send the emails 

This step is the same as previously described. You hit “Send test email” and check your inbox to see if the email was correctly delivered. If yes, click “Send Emails” to proceed with sending it to the entire spreadsheet. 

Tip: If you want to use a proper email-sending service, besides Mailtrap, both Mailchimp and Mailmeteor offer straightforward mail merge options. 

How to test mail merge

Yes, I already said there’s a “Send test email” option and you can use App Script to send only to one recipient. While convenient, this method doesn’t actually cut it, particularly if you’re sending close to Google’s throughput limits. 

Why?


You basically get just a preview and only the results for the email client you sent to. This can lead you to believe that a template, along with merge fields, will work and look the same everywhere. Sadly, this is rarely the case. 

So, you’ll need a tool like Mailtrap Email Testing to check the support for your email templates across all popular email clients. Then, inspect the template spam score and see which email elements (HTML, CSS, etc.) might need your attention to improve email deliverability. 

Mailtrap Email Testing HTML Check

I should stress that Mailtrap Email Testing is part of the Mailtrap Email Delivery Platform. It represents a safe environment to test the emails without spamming your recipients with sandbox emails.

Of course, you can test all the merge fields, links, and attachments if there are any. 

Pro Tip: If you choose to use API, rather than SMTP, you can route emails to Mailtrap Email Testing inboxes from Google Sheets using App Script.  

Alternative to Gmail mail merge

Sure, you can leverage Excel and Word, but it’s best to use a proper email delivery platform such as Mailtrap. You get much more flexibility, and there’s no need to deal with Google or Microsoft quirks. 

Anyway, Mailtrap has a Contacts feature, which, you guessed it, allows you to upload and manage contact details. And you can structure them into different mailing lists for each of your campaigns. 

Mailtrap Contacts feature

For the mail merge, Mailtrap allows you to set different contact variables prior to uploading contacts and then create custom fields for each variable. These can be the recipient’s name, birthday, physical address, or anything else you might need. 

Thereon, you’ll use custom fields for email personalization, where you’ll need to add the following for each field.

  • Field name
  • Type 
  • Merge tag

Besides convenience and more customization options, the key benefit is speed. You don’t need to take as many steps as with Gmail, or other client-based alternatives. 

Wrapping up

When all is said and done, mail merge Gmail gives you a straightforward way to personalize your emails. And it can be a great option for startups and small businesses without extensive email lists. 

But as your business scales, you’ll need to migrate to a proper email-sending platform like Mailtrap to avoid exhausting Google’s limitations too fast. 

Article by Veljko Ristić Content Manager @ Mailtrap

Linguist by trade, digital marketer at heart, I’m a Content Manager who’s been in the online space for 10+ years. From ads to e-books, I’ve covered it all as a writer, editor, project manager, and everything in between. Now, my passion is with email infrastructure with a strong focus on technical content and the cutting-edge in programming logic and flows. But I still like spreading my gospels while blogging purely about marketing.