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 | The script in this guide | |
|---|---|---|
| The email is a Gmail draft, with formatting, images and attachments | Yes | No, plain text in the script |
| Fills in each column name from the row | Yes | Yes |
| Skips rows that already have a status | Yes | Yes |
| Checks what is left of today's limit first | No | Yes |
| When the daily limit runs out | Tries every row left and writes the error into each | Stops, and leaves the rest empty for the next run |
| When Google stops the run at 6 minutes | No status is written for that run | Every email sent so far has its status; it stops itself at 5 minutes |
| Rows a filter hides | Emailed, without the date | Emailed, with the status |
| Access to your Gmail | Read, compose, send and delete | Send only |
| Continues by itself later | No | With a time-driven trigger |
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.
| Limit | A day |
|---|---|
| Gmail, Google Workspace | |
| Apps Script, Google Workspace | |
| Gmail, free gmail.com account | |
| Apps Script, free gmail.com account |
- 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
"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"
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());
}
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
Three things keep a long list safe:
- 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.
- Stop before Google does. Check the clock before each email and end the run at 5 minutes, with every status written.
- 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();
}
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.
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.
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.
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)."
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.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | First name | Amount | Due date | Invoice link | Status | |
| 12 | Maria | maria.lopez@example.com | $60 | Oct 31, 2026 | riversiderowing.example/pay/1012 | Sent 2026-10-14 14:31 |
| 13 | Leo | leo.fischer@example.com | $45 | Oct 31, 2026 | riversiderowing.example/pay/1013 | Sent 2026-10-14 14:31 |
| 37 | Lena | lena@ | $45 | Oct 31, 2026 | riversiderowing.example/pay/1037 | Error: Invalid email: lena@ |
| 102 | Nora | nora.kim@example.org | $60 | Oct 31, 2026 | riversiderowing.example/pay/1102 | Sent 2026-10-14 14:33 |
| 103 | Oscar | oscar.reed@example.com | $45 | Oct 31, 2026 | riversiderowing.example/pay/1103 | |
| 104 | Pia | pia.novak@example.net | $45 | Oct 31, 2026 | riversiderowing.example/pay/1104 |
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 | GmailApp | |
|---|---|---|
| Permission it needs | Sending email, script.send_mail | "Read, compose, send, and permanently delete all your email from Gmail" |
| Reads your drafts and inbox | No | Yes |
| Sends from one of your aliases | No | Yes |
| Cc, Bcc, HTML body, attachments, reply-to | Yes | Yes |
| Tells you what is left of today's limit | Yes | No |
| Counts toward Apps Script's daily email limit | Yes | Yes |
| Emoji and other unicode characters | Yes | Google's sample says to use MailApp |
| Asks for permission again after you edit the script | Less often | More often |
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
- Apps Script: Create a mail merge with Gmail & Google Sheets, read Oct 27, 2026
- Apps Script: Quotas for Google Services, read Oct 27, 2026
- Apps Script: Troubleshooting, read Oct 27, 2026
- Apps Script: Best practices, read Oct 27, 2026
- Apps Script: Installable triggers, read Oct 27, 2026
- Apps Script: Authorization for Google Services, read Oct 27, 2026
- Apps Script: Container-bound scripts, read Oct 27, 2026
- Apps Script reference: Class MailApp, read Oct 27, 2026
- Apps Script reference: Class GmailApp, read Oct 27, 2026
- Apps Script reference: Class SpreadsheetApp, read Oct 27, 2026
- Apps Script reference: Class Spreadsheet, read Oct 27, 2026
- Apps Script reference: Class Sheet, read Oct 27, 2026
- Apps Script reference: Class Range, read Oct 27, 2026
- Apps Script reference: Class LockService, read Oct 27, 2026
- Apps Script reference: Class Lock, read Oct 27, 2026
- Apps Script reference: Class Utilities, read Oct 27, 2026
- Apps Script reference: Class Logger, read Oct 27, 2026
- Apps Script: Advanced Gmail service, read Oct 27, 2026
- Gmail API: Create and send email messages, read Oct 27, 2026
- Google Identity: OAuth 2.0 Scopes for Google APIs, read Oct 27, 2026
- Gmail Help: Limits for sending & getting mail, read Oct 27, 2026
- 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.