Skip to content
HelloRows

A mail merge in Google Apps Script, and the "Service invoked too many times" error

Apps Script can send one email per row of a Google Sheets™ spreadsheet from your Gmail™, to 100 recipients a day on a gmail.com account and 1,500 on Google Workspace™, by Google's figures. Here is what Google's own sample does and doesn't, what the daily limit error means and when it clears, and a short script that writes a status into each row, so a rerun never sends anyone the same email twice.

Short answer

Google says Apps Script can email 100 recipients a day from a gmail.com account and 1,500 from Google Workspace, counted per user and reset "24 hours after the first request." The error "Service invoked too many times for one day: email." means that count is used up. Nothing in the script is broken: the next email waits until the count resets.

Each run also stops after 6 minutes. Write a status into each row as soon as its email goes out, and a stopped run can start again without sending anyone the same email twice.

Google's own Apps Script mail merge sample

Google publishes a ready-made mail merge for Apps Script, "Create a mail merge with Gmail & Google Sheets", marked Beginner and 10 minutes. You copy a sample spreadsheet with the script attached, write the email as a Gmail draft with column names in curly braces, such as {{First name}}, and click Mail Merge, then Send Emails in the sheet's menu. The script asks for the draft's subject line, fills in each row and sends it. In Google's words, "The emails are sent from your Gmail account so that you can respond to recipient replies."

Google warns that "Placeholders are case sensitive and must exactly match the column headers." The code looks for a column named Recipient (the page's setup step says Recipients) and writes the date sent, or the error, into a column named Email Sent. A row whose Email Sent cell is filled in is skipped.

Google's sample next to the script in this guide
Google's sampleThe script in this guide
The email is a Gmail draft, with formatting, images and attachmentsYesNo, plain text in the script
Fills in each column name from the rowYesYes
Skips rows that already have a statusYesYes
Checks what is left of today's limit firstNoYes
When the daily limit runs outTries every row left and writes the error into eachStops, and leaves the rest empty for the next run
When Google stops the run at 6 minutesNo status is written for that runEvery email sent so far has its status; it stops itself at 5 minutes
Rows a filter hidesEmailed, without the dateEmailed, with the status
Access to your GmailRead, compose, send and deleteSend only
Continues by itself laterNoWith a time-driven trigger
The sample column is read from its page and its Code.gs, Apps Script: Create a mail merge with Gmail & Google Sheets, last updated by Google on Sep 3, 2026, read Oct 27, 2026. The script is the one in the section "A mail merge script that never sends twice" below.

The page itself warns of two things: the sample "is subject to the email limits described in" Google's "Quotas for Google Services", and with a filter on, "the script still emails the filtered participants, but it won't add the timestamp." It says nothing about the 6-minute limit.

Two rows of the table come from how the code keeps its record. It collects each row's status as it goes and writes the whole Email Sent column in one go, after the last row:

  • When the daily limit runs out halfway, every send after it fails. The code catches each failure and moves on, so every remaining row gets the error text in Email Sent. The next day it skips those rows, because their cells are no longer empty. Clear those cells before you run it again.
  • When a run reaches 6 minutes, Google stops it before that last write. The emails that went out have no date next to them, and the next run sends them again.

How many emails Apps Script can send a day

Apps Script counts recipients, not emails, for each Google account. Google's "Quotas for Google Services" lists "Email recipients per day (for example, with MailApp)": 100 for a consumer account such as gmail.com, 1,500 for Google Workspace. Gmail's own limit is higher in both cases, and applies as well.

Emails a day: Apps Script's limit and Gmail's, by account
LimitA day
Gmail, Google Workspace2,000messages
Apps Script, Google Workspace1,500recipients
Gmail, free gmail.com account500emails
Apps Script, free gmail.com account100recipients
Bars drawn to scale. Apps Script: "Quotas for Google Services", last updated by Google on Sep 3, 2026. Gmail: Gmail Help and Google Workspace Admin Help. All read Oct 27, 2026.
  • To, Cc and Bcc all count. MailApp's reference says "Quotas are based on the number of email recipients," so one email with one address in Cc uses 2.
  • Inside your own domain, a Workspace account can email 2,000 recipients a day; a gmail.com account stays at 100.
  • One email can go to at most 50 recipients, with a body of at most 200 KB on gmail.com and 400 KB on Workspace.
  • The count is yours, not the script's. Google says the limits "are per user", so every script that runs as you draws on the same 100 or 1,500.
  • Workspace trials have more limits: "Additional limits apply for trial accounts." Google doesn't give their figures. They rise once a converted domain "has cumulatively paid at least USD $100" and 60 days have passed.

The page offers no way to raise them. Google gives the figures "to help test your scripts" and says all of them are "subject to elimination, reduction, or change at any time, without notice."

What "Service invoked too many times for one day: email" means

The error

"Service invoked too many times for one day: email."

It means the script asked to email more recipients than Apps Script allows your account today: the 100 or 1,500 above are used up. None of Google's pages read for this guide prints that exact wording. Google's troubleshooting guide lists its general form, "Service invoked too many times: <action name>", and says it "indicates you exceeded your daily quota for an action, such as sending too many emails." The limits page adds: "If you exceed a quota or limitation, your script throws an exception and execution stops."

It is Apps Script's limit, not Gmail's. When Gmail itself stops your account, it says "You have reached a limit for sending mail", which has its own guide.

Nothing in the code needs fixing. Note who already got the email, wait until the count resets, then send only the rows without a status. If you use Google's sample, clear the Email Sent cells where it wrote this error first, or it will skip those rows.

When the limit resets

Google's limits page gives one sentence: "Quotas are per user and reset 24 hours after the first request." So it is not at midnight. Google doesn't say which request starts those 24 hours, or whether the count comes back all at once. Gmail's own limits are worded differently, as the figure shows.

When each daily limit lets you send again, in Google's words

  • Apps Script, any account"24 hours after the first request"
  • Gmail, Google Workspace"over a rolling 24-hour period"
  • Gmail, gmail.com"within 1 to 24 hours"
Each row quotes the page that sets the limit: Apps Script's "Quotas for Google Services" and Gmail Help, read Oct 27, 2026, and Google Workspace Admin Help, last updated by Google on Nov 10, 2026, read Nov 21, 2026. None of them names a clock time.

How to see what is left today

MailApp has a method for it. MailApp.getRemainingDailyQuota() "Returns the number of recipients you can send emails to for the rest of the day." Paste this into the sheet's script (Extensions, then Apps Script), choose emailsLeftToday and click Run.

How many recipients your account can still email today

// Shows how many recipients this account can still email today.
// Choose emailsLeftToday at the top of the editor, click Run,
// then read the number in the Execution log.
function emailsLeftToday() {
  Logger.log(MailApp.getRemainingDailyQuota());
}
Written from the Apps Script reference for MailApp and Logger, read Oct 27, 2026. On a gmail.com account with nothing sent yet, Google's figure is 100.

Google adds that the number "is valid for the current execution and might vary between executions," so read it at the start of each run rather than once a day. It needs the same permission as sending with MailApp, so a MailApp script asks for nothing more.

The 6-minute limit on a long list

Google lists one more limit that matters for a mail merge: "Script runtime", 6 minutes per execution on every account. A run still going at 6 minutes is stopped where it is, and anything it kept only in memory is gone. Google doesn't say how long one email takes to send, so no fixed number of rows fits into 6 minutes; the higher your daily limit, the more likely a run gets there.

A run that reaches 6 minutes, and what the next run does

  • Statuses saved for the endGoogle stops the run at 6 minutesNo row of that run says Sent, so the next run sends them again
  • A status written after each emailThe run stops itself at 5 minutesThe next run starts at the first empty status
The first row is how Google's sample keeps its record, the second how the script below does. The 6 minutes: "Quotas for Google Services", read Oct 27, 2026.

Three things keep a long list safe:

  1. Write each status as soon as its email goes out. Google's best-practice guide says the opposite for speed: "Alternating read and write commands is slow." For a mail merge, slow is the right trade. A status still in memory is lost when the run stops.
  2. Stop before Google does. Check the clock before each email and end the run at 5 minutes, with every status written.
  3. Let a timer start the next run. A time-driven trigger runs a function "as frequently as every minute or as infrequently as once per month," Google says. Triggers have a daily limit of their own: 90 minutes of run time a day on gmail.com, 6 hours on Workspace.

A mail merge script that never sends twice

This script sends with MailApp and keeps the email in the script, not in a Gmail draft. It writes Sent with the time, or the error, into a Status column as soon as each email goes out. It stops by itself before the daily limit and before the 6 minutes, and leaves every row it didn't send empty for the next run. A shorter one, without the clock and the lock, is in the guide to mail merge from Google Sheets to Gmail.

One email per row, a status after each, safe to run again

// Asks for access to this one spreadsheet, not to all of your spreadsheets.
/**
 * @OnlyCurrentDoc
 */
// Your tab and your email. Each {{Column name}} is replaced with that
// column's value in the row being sent; names must match row 1 exactly.
const SHEET_NAME = 'Members';
const SUBJECT = 'Membership fee due {{Due date}}';
const BODY = 'Hi {{First name}},\n\n' +
  'Your Riverside Rowing Club fee of {{Amount}} is due on {{Due date}}.\n' +
  'You can pay it here: {{Invoice link}}\n\n' +
  'Thanks,\nAnna';
// Google stops every run at 6 minutes. This script stops at 5 (written
// in milliseconds), which leaves time to write the last status.
const STOP_AFTER_MS = 5 * 60 * 1000;
function sendEmails() {
  // A timed run and a click on Run at the same moment could both send
  // the same row, so only one run at a time gets past this point.
  const lock = LockService.getScriptLock();
  if (lock.tryLock(1000) === false) return;
  const started = Date.now();
  const spreadsheet = SpreadsheetApp.getActive();
  // By name, because a timed run has no tab open on screen.
  const sheet = spreadsheet.getSheetByName(SHEET_NAME);
  if (sheet === null) throw new Error('No tab named ' + SHEET_NAME);
  // The values as the sheet shows them; row 1 holds the column names.
  const rows = sheet.getDataRange().getDisplayValues();
  const names = rows[0];
  const emailCol = names.indexOf('Email');
  const statusCol = names.indexOf('Status');
  // Check every column name before the first email goes out.
  const tags = (SUBJECT + BODY).match(/\{\{.+?\}\}/g) || [];
  const needed = ['Email', 'Status', ...tags.map((tag) => tag.slice(2, -2))];
  const missing = needed.filter((name) => names.includes(name) === false);
  if (missing.length > 0) throw new Error('No column named ' + missing.join(', '));
  const zone = spreadsheet.getSpreadsheetTimeZone();
  let left = MailApp.getRemainingDailyQuota(); // recipients still allowed today
  for (let i = 1; i < rows.length; i++) {
    const row = rows[i];
    if (row[statusCol]) continue;                    // has a status: never again
    if (row[emailCol] === '') continue;              // no address in this row
    if (left < 1) break;                             // today's limit is used up
    if (Date.now() - started > STOP_AFTER_MS) break; // the rest in the next run
    const fill = (text) =>
      text.replace(/\{\{(.+?)\}\}/g, (tag, name) => row[names.indexOf(name)]);
    let status;
    try {
      MailApp.sendEmail(row[emailCol], fill(SUBJECT), fill(BODY));
      left -= 1;
      status = 'Sent ' + Utilities.formatDate(new Date(), zone, 'yyyy-MM-dd HH:mm');
    } catch (error) {
      // The daily limit said no: leave this row empty for the next run.
      if (error.message.includes('Service invoked too many times')) break;
      status = 'Error: ' + error.message;            // a bad address, for example
    }
    // Write the status now, not at the end, so a run that stops
    // never loses the record of who already got the email.
    sheet.getRange(i + 1, statusCol + 1).setValue(status);
    SpreadsheetApp.flush();
  }
  lock.releaseLock();
}
For the example sheet: a tab named Members with columns named Email and Status, one address per Email cell, and a column for every column name in SUBJECT and BODY. Written from Google's Apps Script reference for MailApp, SpreadsheetApp, Spreadsheet, Sheet, Range, Lock, LockService and Utilities, and the guide to authorization, read Oct 27, 2026.
  1. Set up the sheet

    Row 1 holds the column names. Add a column named Status and leave it empty: the script fills it in. Put one address in each Email cell; the script counts one recipient per row.

  2. Paste the script

    In the sheet, click Extensions, then Apps Script. Replace what is there with the script, change SHEET_NAME, SUBJECT and BODY to your own, and save.

  3. Try it on yourself first

    Duplicate the tab, keep only a row with your own address, and set SHEET_NAME to the copy's name. Run it, check the email, then set SHEET_NAME back.

  4. Run it and allow access

    Choose sendEmails and click Run. The first time, Google asks for permission. For a script of your own it may warn "This app isn't verified"; Google's sample page says to continue with Advanced, then "Go to {Project Name} (unsafe)."

  5. Let it carry on by itself

    At the left of the editor, click Triggers, then Add Trigger. Choose sendEmails and a time-driven trigger that runs every hour, and save. Each hour it sends what today's limit allows and stops. Once every row has a status, delete the trigger.

ABCDEF
1First nameEmailAmountDue dateInvoice linkStatus
12Mariamaria.lopez@example.com$60Oct 31, 2026riversiderowing.example/pay/1012Sent 2026-10-14 14:31
13Leoleo.fischer@example.com$45Oct 31, 2026riversiderowing.example/pay/1013Sent 2026-10-14 14:31
37Lenalena@$45Oct 31, 2026riversiderowing.example/pay/1037Error: Invalid email: lena@
102Noranora.kim@example.org$60Oct 31, 2026riversiderowing.example/pay/1102Sent 2026-10-14 14:33
103Oscaroscar.reed@example.com$45Oct 31, 2026riversiderowing.example/pay/1103
104Piapia.novak@example.net$45Oct 31, 2026riversiderowing.example/pay/1104
The Members tab after the first day's run from anna.berg@gmail.com. Rows 12, 13 and 102 say Sent with the time. Row 37 has no full address, so it says why and is not tried again until you fix the cell and clear its status. Rows 2 to 102 hold one error and 100 sent emails, which used up the day's 100 recipients, so row 103 is the first empty status and the next run starts there. The error text follows Google's troubleshooting guide. Example data.

What it doesn't do: it sends plain text, it has no preview, and it emails rows a filter hides. HelloRows, the add-on this site makes, does those three: the email can carry links, lists and a button, any row can be previewed and sent to you as a test, and it can send to only the rows in the current filter. If Gmail itself refuses an email, rather than Apps Script, that row gets an Error status like any other failure; clear it to send it again.

MailApp.sendEmail or GmailApp.sendEmail

Both send an email from your account with the same call, sendEmail(recipient, subject, body), and both take options for Cc, Bcc, an HTML body, attachments, a reply-to address and the sender's name. The difference is what else each can reach, and so what Google asks you to allow.

MailApp and GmailApp, side by side
MailAppGmailApp
Permission it needsSending email, script.send_mail"Read, compose, send, and permanently delete all your email from Gmail"
Reads your drafts and inboxNoYes
Sends from one of your aliasesNoYes
Cc, Bcc, HTML body, attachments, reply-toYesYes
Tells you what is left of today's limitYesNo
Counts toward Apps Script's daily email limitYesYes
Emoji and other unicode charactersYesGoogle's sample says to use MailApp
Asks for permission again after you edit the scriptLess oftenMore often
Sources: Apps Script reference for MailApp and GmailApp (last updated by Google on Apr 13, 2026), Google's OAuth 2.0 scopes list for the GmailApp permission, and the mail merge sample, which sends with GmailApp and "is subject to the email limits." All read Oct 27, 2026.

Google's reference puts MailApp plainly: its "sole purpose is sending email" and it "cannot access a user's Gmail inbox." GmailApp "Provides access to Gmail threads, messages, and labels," which is why its permission covers your whole mailbox. It also adds a from option, which must be one of the addresses GmailApp.getAliases() returns.

Use MailApp unless you need a Gmail draft as the email or a send-as alias. Google's sample needs the draft, which is why it asks for full Gmail access. Google also notes: "Changes to scripts written using GmailApp are more likely to trigger a re-authorization request from a user than MailApp scripts." HelloRows asks for the narrower kind too: a Gmail permission that can only send, and access to only the spreadsheet it is opened in and the Google Drive files you pick for attachments.

Gmail's own daily limit, on top

A script's emails go out from your Gmail account, as Google's sample page puts it, so Gmail's limit is there too. Gmail Help says Gmail "limits the number of emails you can send or get per day" and names "more than 500 emails sent in a day" for a gmail.com account. Google Workspace allows 2,000 messages a day per user, 1,500 through Gmail's mail merge and 500 on a trial. What counts toward them is in Gmail sending limits.

Google publishes the two limits on separate pages and doesn't say how they add up. Google Workspace Admin Help notes only: "Quotas might be different if you're using Google Apps Script." On gmail.com, Apps Script's 100 comes first. On Workspace, a script's 1,500 and your own mail together can come near Gmail's 2,000, so leave room for both.

The Gmail API, a second way to send

Apps Script also has an Advanced Gmail service, which "lets you use the Gmail API in Google Apps Script" and "must be enabled before use." On Oct 14, 2026, in a test for HelloRows, the add-on this site makes, Gmail accepted 120 of 120 emails sent through the Gmail API from one gmail.com account, while MailApp's counter still read 100. It is one test on one account, but those sends were not held to Apps Script's 100; Gmail's own limit still applies to them.

It takes more code. Google's Gmail API guide says it "requires MIME email messages compliant with RFC 2822 and encoded as base64URL strings," so the script has to build each email itself. More on this in Why some add-ons stop at 100 a day.

Questions

How do I fix "Service invoked too many times for one day: email"?

Nothing in the code is broken: the script used up Apps Script's daily email limit, which Google puts at 100 recipients a day on a gmail.com account and 1,500 on Google Workspace. Google says the limit resets 24 hours after the first request. Meanwhile, note who already got the email, then run the script again on the rows without a status. If you used Google's mail merge sample, first clear the Email Sent cells where it wrote the error.

How many emails can Google Apps Script send per day?

Google lists 100 email recipients a day for a consumer account such as gmail.com and 1,500 for Google Workspace, or 2,000 to addresses inside your own Workspace domain. It counts recipients, so Cc and Bcc count too, and one email can go to at most 50. Gmail's own limit, 500 a day on gmail.com and 2,000 on Workspace, applies to your account as well.

When does the Apps Script email limit reset?

Google says Apps Script's limits are per user and "reset 24 hours after the first request", so not at midnight. Google doesn't describe the timing any further. To see where you stand, run MailApp.getRemainingDailyQuota(), which returns the number of recipients you can still email today.

What is the difference between MailApp and GmailApp?

Both send email from your account. MailApp only sends, and Google says it "cannot access a user's Gmail inbox." GmailApp can also read your drafts, threads and labels and send from an alias, so it asks for permission to read, compose, send and permanently delete all your Gmail. Both count toward Apps Script's daily email limit; only MailApp can tell you what is left of it.

How do I get around the 6-minute limit in Apps Script?

One run can't last longer: Google lists 6 minutes per execution for every account. Split the work instead. Write each row's status as soon as its email goes out, end the run a little before 6 minutes, and let a time-driven trigger start the next run, which carries on at the first row without a status.

Sources

  1. Apps Script: Create a mail merge with Gmail & Google Sheets, read Oct 27, 2026
  2. Apps Script: Quotas for Google Services, read Oct 27, 2026
  3. Apps Script: Troubleshooting, read Oct 27, 2026
  4. Apps Script: Best practices, read Oct 27, 2026
  5. Apps Script: Installable triggers, read Oct 27, 2026
  6. Apps Script: Authorization for Google Services, read Oct 27, 2026
  7. Apps Script: Container-bound scripts, read Oct 27, 2026
  8. Apps Script reference: Class MailApp, read Oct 27, 2026
  9. Apps Script reference: Class GmailApp, read Oct 27, 2026
  10. Apps Script reference: Class SpreadsheetApp, read Oct 27, 2026
  11. Apps Script reference: Class Spreadsheet, read Oct 27, 2026
  12. Apps Script reference: Class Sheet, read Oct 27, 2026
  13. Apps Script reference: Class Range, read Oct 27, 2026
  14. Apps Script reference: Class LockService, read Oct 27, 2026
  15. Apps Script reference: Class Lock, read Oct 27, 2026
  16. Apps Script reference: Class Utilities, read Oct 27, 2026
  17. Apps Script reference: Class Logger, read Oct 27, 2026
  18. Apps Script: Advanced Gmail service, read Oct 27, 2026
  19. Gmail API: Create and send email messages, read Oct 27, 2026
  20. Google Identity: OAuth 2.0 Scopes for Google APIs, read Oct 27, 2026
  21. Gmail Help: Limits for sending & getting mail, read Oct 27, 2026
  22. Google Workspace Admin Help: Gmail sending limits in Google Workspace, last updated Nov 10, 2026, read Nov 21, 2026

Who wrote this

Adam Martiník makes HelloRows, a Google Sheets™ add-on that sends one email per row from your own Gmail. Like the script here, it writes each row's status into the sheet and skips the rows that already say Sent; its free plan sends up to 50 emails a day, and a longer run continues by itself after midnight.