MAILMERGEGENERATOR
Generate a ready-to-use Google Apps Script for mail merge directly from your browser. No add-ons required.
Why Mail Merge Script Generator?
No Add-ons Required
Generate vanilla Google Apps Script that you own. Run it directly from your own Google account.
Use Custom Merge Fields
Personalize your emails with any column from your spreadsheet using {{Column Name}} syntax.
100% Privacy
This tool runs completely in your browser. We never see your spreadsheet data, emails, or templates.
Go further with Pro
These Google Workspace add-ons install in seconds and automate workflows you're still doing manually.
Intelligent AutoCrat
AI-Native Form → Document Workflow Addon. Turn Google Forms submissions into customized, contextually appropriate documents generated by AI.
Learn moreSemantic Sheets
AI Sheet Data Intelligence Addon. Bring semantic understanding to Google Sheets to instantly clean, classify, and extract unstructured data.
Learn moreTalentDesk
Your hiring desk, inside Google Sheets. An AI-powered hiring workflow system that automates candidate evaluation, resume scoring, and interview preparation.
Learn moreWhy this tool exists
You want to send personalized emails from Google Sheets, but don't want to pay for expensive mail merge add-ons like YAMM just to run a simple script. Plus, you want full control over your data.
Most mail merge add-ons cost a monthly fee and require extensive permissions to read your emails and spreadsheets. By using a custom Apps Script, the code lives entirely in your Google account. Here is how to use it:
- Prepare your data: Ensure your Google Sheet has a header row with columns like
First NameorEmail Address. - Draft your template: Fill out the form here with your desired subject and body using
{{Column Header}}to inject custom data. - Copy the script: Click "Copy Code" to get your personalized Mail Merge script.
- Install in Sheets: Open your Google Sheet, click Extensions > Apps Script, paste the code, and hit Save.
- Send: Refresh your spreadsheet to see a new custom Mail Merge menu at the top. Click it to send!
Need a more powerful version?
Explore Pro toolsThe exact name of the column containing recipient emails.
function sendMailMerge() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
if (data.length < 2) {
SpreadsheetApp.getUi().alert("Not enough data in the sheet.");
return;
}
const headers = data[0];
const emailColIndex = headers.indexOf("Email Address");
if (emailColIndex === -1) {
SpreadsheetApp.getUi().alert("Could not find column named 'Email Address'. Please check your headers.");
return;
}
const templateSubject = "Update for {{First Name}}";
const templateBody = `Hi {{First Name}},\n\nHere is your custom link: {{Custom Link}}\n\nBest,\nTeam`;
let emailsSent = 0;
for (let i = 1; i < data.length; i++) {
const row = data[i];
const emailAddress = row[emailColIndex];
if (!emailAddress || String(emailAddress).trim() === "") continue;
let currentSubject = templateSubject;
let currentBody = templateBody;
// Replace all {{Header}} with actual row data
for (let j = 0; j < headers.length; j++) {
const header = headers[j];
const value = row[j] || "";
const regex = new RegExp("\\{\\{" + escapeRegExp(String(header)) + "\\}\\}", "gi");
currentSubject = currentSubject.replace(regex, value);
currentBody = currentBody.replace(regex, value);
}
try {
MailApp.sendEmail({
to: String(emailAddress),
subject: currentSubject,
body: currentBody
});
emailsSent++;
} catch (e) {
Logger.log("Failed to send to " + emailAddress + ": " + e.toString());
}
}
SpreadsheetApp.getUi().alert("Successfully sent " + emailsSent + " emails!");
}
function escapeRegExp(string) {
return string.replace(/[.*+?^$\{\}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
function onOpen() {
SpreadsheetApp.getUi().createMenu('Mail Merge')
.addItem('Send Emails', 'sendMailMerge')
.addToUi();
}
Get every new tool on launch day
We ship one or two free tools every week. Subscribe and be the first to use them.
Free updates. No spam. Unsubscribe any time.
You might also like
More Google Workspace tools built to save you hours every single week.
Email List Cleaner
Paste any messy text and instantly extract, deduplicate, and validate a clean list of emails.
Learn moreIntelligent AutoCrat
AI-Native Form → Document Workflow Addon. Turn Google Forms submissions into customized, contextually appropriate documents generated by AI.
Learn moreSemantic Sheets
AI Sheet Data Intelligence Addon. Bring semantic understanding to Google Sheets to instantly clean, classify, and extract unstructured data.
Learn more