r/GoogleAppsScript • u/Independent_Chance34 • May 13 '26
Question How do you preserve a custom email design/layout while using mail merge with Gmail + Google Sheets?
Hi, beginner here. I recently learned how to do mail merge using Gmail and Google Sheets, but I can only send plain text emails so far.
Our team now wants to send emails with a customized layout/design using the email layout feature of Gmail while still automatically inserting data from our database such as the recipient’s name and verification code.
I’m confused about how to preserve the email design/template while still doing automated mail merge sending. We have Google workspace access if that could help?
Any tips or help.
Thank you.
2
u/elephantyan 9d ago
Don't rebuild the layout in Apps Script. Design the email as a Gmail draft with placeholders like {{name}} and {{code}}. Then in the script: find that draft with GmailApp.getDrafts(), grab getMessage().getBody() for the HTML, replace the placeholders from each sheet row, and send with GmailApp.sendEmail(to, subject, plainText, {htmlBody: html}). Keep the CSS inline and simple, because Gmail strips <style> blocks in a lot of clients. Test on 3 rows first.
(If you'd rather not maintain the script, I built a pay-once sheet that does this plus follow-ups from your own Gmail. Happy to share it, but the above works fine for free.)
2
u/SlaVKs May 13 '26
Use the designed Gmail message as an HTML template instead of rebuilding the layout in Apps Script.
A simple pattern is:
Rough shape:
const draft = GmailApp.getDrafts().find(d => d.getMessage().getSubject() === 'TEMPLATE SUBJECT'); const html = draft.getMessage().getBody();
const personalized = html .replaceAll('{{name}}', row.name) .replaceAll('{{code}}', row.code);
GmailApp.sendEmail(row.email, 'Your subject', 'Plain text fallback', { htmlBody: personalized });
A few gotchas: Gmail may strip some CSS, so keep styles inline/simple; use a plain-text fallback; and do not test with real verification codes or private user data until the template works with dummy rows.
1
u/Living-Tackle-8198 May 15 '26
Look into Templates. Practice first by using them directly and see how you can build a reusable email base with links, images, two-column sections, etc.