Send Email from Google Sheets with Apps Script (Mail Merge)

Send email from Google Sheets with a short Apps Script mail merge: personalized messages, a test button, sent status tracking and quota checks.

Send Email from Google Sheets with Apps Script (Mail Merge)

Invoice reminders, appointment confirmations, onboarding notes, event updates: if the details already live in a spreadsheet, you should not be copying them into Gmail one message at a time. In this guide you will learn how to send email from Google Sheets with a short Apps Script mail merge. Each row becomes a personalized email, a Status column records what was sent so nobody gets a message twice, and a custom menu lets anyone on your team run it with two clicks.

You do not need any add-ons or paid tools. Apps Script is built into every Google Sheet and works with both free Gmail and Google Workspace accounts.

Set up the sheet for your mail merge

Create a sheet tab named Recipients with one header row. The script uses the header names as placeholders, so keep them short and without spaces. For an invoice reminder, these columns work well:

Name Email Invoice Amount DueDate Status
Maria maria@example.com INV-1042 $1,250.00 Nov 15, 2026
James james@example.com INV-1043 $480.00 Nov 18, 2026

Format the Amount and DueDate columns exactly as you want them to appear in the email. The script reads the displayed values, so “$1,250.00” stays “$1,250.00” instead of turning into 1250. Leave the Status column empty. The script writes “Sent” there after each successful email.

Add the Apps Script code

  1. In your spreadsheet, choose Extensions, Apps Script. A new browser tab opens with a code editor.
  2. Delete the empty function in Code.gs and paste the full script below.
  3. Edit the SUBJECT and BODY templates. Any header name wrapped in double curly braces, such as {{Name}}, is replaced with that row’s value.
  4. Click the save icon, then return to the spreadsheet and reload the page. A new Mail Merge menu appears next to Help.
// Mail merge from Google Sheets: one personalized email per row
const SHEET_NAME = 'Recipients';
const SENDER_NAME = 'Accounts Team';

const SUBJECT = 'Reminder: invoice {{Invoice}} is due on {{DueDate}}';
const BODY =
  'Hi {{Name}},nn' +
  'This is a friendly reminder that invoice {{Invoice}} for {{Amount}} ' +
  'is due on {{DueDate}}.nn' +
  'If you have already paid, please ignore this message.nn' +
  'Thank you,nAccounts Team';

// Adds a custom menu when the spreadsheet opens
function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Mail Merge')
    .addItem('Send test email to me', 'sendTestEmail')
    .addItem('Send emails', 'sendEmails')
    .addToUi();
}

// Replaces every {{Header}} in the template with the row's value
function fillTemplate(template, headers, row) {
  let text = template;
  headers.forEach((header, i) => {
    text = text.split('{{' + header + '}}').join(row[i]);
  });
  return text;
}

// Reads the sheet as displayed (formatted dates and currency)
function getRows() {
  const sheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME);
  const rows = sheet.getDataRange().getDisplayValues();
  return { sheet: sheet, headers: rows[0], rows: rows };
}

function sendEmails() {
  const { sheet, headers, rows } = getRows();
  const emailCol = headers.indexOf('Email');
  const statusCol = headers.indexOf('Status');
  if (emailCol === -1 || statusCol === -1) {
    throw new Error('The sheet needs an Email column and a Status column.');
  }

  let sent = 0;
  for (let r = 1; r < rows.length; r++) {
    const row = rows[r];
    const email = row[emailCol].trim();
    if (!email || row[statusCol] !== '') continue;   // skip blanks and processed rows

    if (MailApp.getRemainingDailyQuota() < 1) {
      SpreadsheetApp.getUi().alert('Daily email quota reached. Run again tomorrow.');
      break;
    }

    try {
      MailApp.sendEmail({
        to: email,
        subject: fillTemplate(SUBJECT, headers, row),
        body: fillTemplate(BODY, headers, row),
        name: SENDER_NAME
      });
      sheet.getRange(r + 1, statusCol + 1).setValue('Sent');
      sent++;
    } catch (err) {
      sheet.getRange(r + 1, statusCol + 1).setValue('Error: ' + err.message);
    }
  }
  SpreadsheetApp.getUi().alert(sent + ' email(s) sent.');
}

// Sends the first data row's email to you only, so you can check it
function sendTestEmail() {
  const { headers, rows } = getRows();
  const me = Session.getActiveUser().getEmail();
  MailApp.sendEmail({
    to: me,
    subject: '[TEST] ' + fillTemplate(SUBJECT, headers, rows[1]),
    body: fillTemplate(BODY, headers, rows[1]),
    name: SENDER_NAME
  });
  SpreadsheetApp.getUi().alert('Test email sent to ' + me);
}

How the script works

The getDisplayValues() call reads every cell exactly as it appears on screen, which is why dates and currency look right in the email. fillTemplate loops over the headers and swaps each placeholder for the matching value, so you can add a new column, such as {{Company}}, and use it in the template without changing any other code.

The Status column is the safety net. A row is skipped if its status is not empty, and “Sent” is written immediately after each email. If the script stops halfway, running it again picks up where it left off without sending duplicates. To resend to someone, simply clear their Status cell.

Run it safely the first time

  1. Choose Mail Merge, Send test email to me. Google asks you to authorize the script the first time.
  2. On the authorization screen, choose your account. For a script you wrote yourself, Google may show “Google hasn’t verified this app”. Click Advanced and then the link to continue to your project.
  3. Check the test email in your inbox: names, amounts and dates should all look right.
  4. Add yourself as the first two rows of the sheet and run Send emails for a real end-to-end test.
  5. Remove your test rows, clear any Status cells and run it for real.

Optional: send HTML emails with formatting

Plain text is the most reliable for deliverability, but you can add bold text, links or a simple layout with the htmlBody option. Keep the plain body as a fallback for email clients that block HTML:

const HTML_BODY =
  '<p>Hi {{Name}},</p>' +
  '<p>Invoice <strong>{{Invoice}}</strong> for <strong>{{Amount}}</strong> ' +
  'is due on {{DueDate}}.</p>' +
  '<p>Thank you,<br>Accounts Team</p>';

// Inside sendEmails(), add one line to the sendEmail options:
//   htmlBody: fillTemplate(HTML_BODY, headers, row),

If your sheet values could contain characters like < or &, clean them first, because they are inserted into the HTML as they are.

Gmail sending limits and quotas

Google limits how many recipients a script can email per day. At the time of writing, consumer Gmail accounts get 100 recipients per day through Apps Script, and Google Workspace accounts get 1,500. Each script run can also last about six minutes at most. Check the current numbers on Google’s Apps Script quotas page.

The script checks MailApp.getRemainingDailyQuota() before every email and stops cleanly when you run out. Because sent rows are marked, you can simply run it again the next day.

Common mistakes to avoid

  • Header names that do not match the placeholders. {{DueDate}} will not fill if the header says “Due Date”. Spelling and spaces must match exactly.
  • Using getValues instead of getDisplayValues. Dates then appear as long timestamps like “Sun Nov 15 2026 00:00:00 GMT”, which looks unprofessional.
  • Skipping the test email. One typo in a template goes to every recipient. Always send yourself a test first.
  • Sending to a pasted list without consent. Mail merge is for people who expect to hear from you, like customers and members, not for cold bulk email.
  • Renaming the sheet tab. If you rename Recipients, update SHEET_NAME in the script, or nothing will send.

Frequently asked questions

Can I attach a PDF to each email?

Yes. Store the Google Drive file ID in a column, then pass attachments: [DriveApp.getFileById(id).getAs(MimeType.PDF)] in the sendEmail options. The script will ask for Drive permission the next time it runs.

Can I schedule the emails to send automatically?

Yes. In the Apps Script editor, open Triggers (the clock icon), add a time-driven trigger for sendEmails and choose a daily or hourly schedule. Remove the alert lines first, because pop-ups cannot appear when nobody has the sheet open.

Will the emails come from my Gmail address?

Yes. MailApp sends from the account that runs the script, and the messages appear in your Sent folder. The name option only changes the display name.

Can I do the same thing from Excel?

Yes, with VBA and Outlook. I explain that approach in my guide to sending personalized emails from Excel with Outlook VBA.

Want this done for you?

If you need reminders that send on a schedule, attach invoices from Drive or update a CRM after each email, I build these through my Google Sheets and Apps Script service. You can get an instant quote in a couple of minutes.

12 Excel VBA macros that save hours every week

The small macros I use on almost every client file. One .bas file you import once, with clear comments and step by step instructions.

  • Unhide, protect and unprotect all sheets
  • Delete blank rows and clean messy text
  • Highlight duplicates in any range
  • Split one sheet into many by a column
  • Combine every sheet into one
  • Export each sheet to its own PDF
  • Clickable sheet index, dated backups and a formula audit list

No spam. Your email is never shared. Privacy Policy

Sourab Saha, Data Analyst

About the author

Sourab Saha · Data Analyst · Kolkata, India

I’m Sourab Saha, a data analyst and automation developer from Kolkata, India, with more than ten years of experience turning manual data work into clean, automated systems. On Fiverr and Upwork I have delivered over 500 data and automation projects for clients in the US, UK, Europe, Australia and the Middle East, with a 5.0 rating on both platforms. My toolkit is Excel VBA, SQL, Power BI and DAX, Python with Selenium, and Google Apps Script. I collect data from files, databases and websites, clean it, model it and present it so decisions take minutes instead of days. I build and test every tool on your real data, deliver it with a short walkthrough, and keep revising until it works exactly the way you need. Alongside my freelance work, since 2024 I have also worked as a Data Analyst for AH Group of Industries, a US healthcare group, building automated reports and Power BI dashboards from billing, payroll, audit and attendance data.

Rated 5.0 on Fiverr and Upwork, with more than 500 automation projects delivered and over ten years of Excel VBA. You get a fixed price before any work starts, your files stay private on your order page, and every order comes with a proper invoice.

WhatsApp