Send an HTML Email

GmailApp.sendEmail() supports an htmlBody option that lets you send richly formatted emails with styles, tables, links, and dynamic content — far beyond plain text.

Basic HTML Email

function sendBasicHtmlEmail() { var recipient = "[email protected]"; var subject = "Your Pro Plan is Active!"; var htmlBody = ` <h2>Welcome to Acme Corp, Sarah!</h2> <p>Your <strong>Pro Plan</strong> subscription is now active.</p> <p>If you have any questions, reply to this email or contact your account manager.</p> <br> <p>Best regards,<br>The Acme Corp Team</p> `; GmailApp.sendEmail(recipient, subject, "", { htmlBody: htmlBody }); Logger.log("Email sent to " + recipient); }

The third argument is the plain-text fallback (left empty here). Always provide one for email clients that don't render HTML.

HTML Email with a Styled Data Table

This example sends a deal summary to a sales rep with a formatted table:

function sendDealSummaryEmail() { var salesRep = "[email protected]"; var subject = "Your Closed Deals – March 2024"; var htmlBody = ` <h2>March 2024 – Closed Deals Summary</h2> <p>Hi Alex,</p> <p>Here's a summary of your closed deals this month:</p> <table border="1" cellpadding="8" cellspacing="0" style="border-collapse:collapse; font-family:Arial, sans-serif;"> <thead style="background-color:#4A90D9; color:#ffffff;"> <tr> <th>Customer</th> <th>Product</th> <th>Amount</th> <th>Region</th> <th>Date</th> </tr> </thead> <tbody> <tr> <td>Sarah Johnson</td> <td>Pro Plan</td> <td>$299/mo</td> <td>North</td> <td>Mar 15, 2024</td> </tr> </tbody> </table> <br> <p>Total closed: <strong>$299</strong></p> <p>Keep up the great work!</p> `; GmailApp.sendEmail(salesRep, subject, "See your closed deals summary (HTML view required).", { htmlBody: htmlBody }); Logger.log("Summary sent to " + salesRep); }

Generating the Table Dynamically from a Sheet

function sendDynamicSummaryEmail() { var sheet = SpreadsheetApp .getActiveSpreadsheet() .getSheetByName("Sales Tracker"); var data = sheet.getRange(2, 1, sheet.getLastRow() - 1, 8).getValues(); // Columns: [Customer Name, Email, Product, Amount, Region, Sales Rep, Status, Date] var salesRep = "[email protected]"; var repName = "Alex Martinez"; var rows = data .filter(function(row) { return row[5] === repName && row[6] === "Closed"; }) .map(function(row) { return `<tr> <td>${row[0]}</td> <td>${row[2]}</td> <td>$${row[3]}/mo</td> <td>${row[4]}</td> <td>${Utilities.formatDate(new Date(row[7]), Session.getScriptTimeZone(), "MMM dd, yyyy")}</td> </tr>`; }).join(""); var htmlBody = ` <h2>Your Closed Deals – March 2024</h2> <p>Hi ${repName},</p> <table border="1" cellpadding="8" cellspacing="0" style="border-collapse:collapse;"> <thead style="background-color:#4A90D9; color:#fff;"> <tr><th>Customer</th><th>Product</th><th>Amount</th><th>Region</th><th>Date</th></tr> </thead> <tbody>${rows}</tbody> </table> `; GmailApp.sendEmail(salesRep, "Your Closed Deals – March 2024", "", { htmlBody: htmlBody }); Logger.log("Email sent to " + salesRep); }

Adding CC and BCC

GmailApp.sendEmail(recipient, subject, plainText, { htmlBody: htmlBody, cc: "[email protected]", bcc: "[email protected]", name: "Acme Corp Sales Team", replyTo: "[email protected]" });