Create Email Drafts

GmailApp.createDraft() lets you create email drafts that land in your Gmail Drafts folder — ready for you to review and send manually. This is useful when you want a human to approve emails before they go out, or when preparing a batch of personalised emails for review.

Creating a Basic Draft

function createBasicDraft() { GmailApp.createDraft( "[email protected]", "Following Up – Pro Plan", "Hi Sarah,\n\nJust checking in to see how your Pro Plan onboarding is going.\n\nBest,\nAlex" ); Logger.log("Draft created."); }

The draft appears in your Gmail Drafts folder immediately.

Creating an HTML Draft

function createHtmlDraft() { var htmlBody = ` <p>Hi Sarah,</p> <p>Just checking in to see how your <strong>Pro Plan</strong> onboarding is going.</p> <p>Let us know if you need anything!</p> <br> <p>Best regards,<br><strong>Alex Martinez</strong><br>Acme Corp – North Region</p> `; GmailApp.createDraft( "[email protected]", "Following Up – Pro Plan", "Hi Sarah, just checking in on your Pro Plan onboarding.", { htmlBody: htmlBody } ); Logger.log("HTML draft created."); }

Generating Follow-Up Drafts for In-Progress Deals

This example reads all In Progress deals from the Sales Tracker and creates a personalised follow-up draft for each:

function createFollowUpDrafts() { 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] data.forEach(function(row) { var customerName = row[0]; var customerEmail = row[1]; var product = row[2]; var salesRep = row[5]; var status = row[6]; if (status !== "In Progress") return; var firstName = customerName.split(" ")[0]; var subject = "Following Up – Your " + product + " Evaluation"; var htmlBody = ` <p>Hi ${firstName},</p> <p>I wanted to follow up on your <strong>${product}</strong> evaluation with Acme Corp.</p> <p>Do you have any questions or would you like to schedule a quick call to discuss next steps?</p> <br> <p>Best regards,<br><strong>${salesRep}</strong></p> `; var plainText = "Hi " + firstName + ",\n\nI wanted to follow up on your " + product + " evaluation. Do you have any questions?\n\nBest,\n" + salesRep; GmailApp.createDraft(customerEmail, subject, plainText, { htmlBody: htmlBody }); Logger.log("Draft created for: " + customerName); }); }

With the sample data, a follow-up draft is created for Mark Chen (Enterprise Plan, In Progress). Sarah and Lisa are skipped as their status is Closed.

Creating a Draft with CC and Attachment

function createDraftWithCC() { var file = DriveApp.getFileById("YOUR_PROPOSAL_FILE_ID"); GmailApp.createDraft( "[email protected]", "Acme Corp – Enterprise Plan Proposal", "Please find our Enterprise Plan proposal attached.", { cc: "[email protected]", attachments: [file.getAs(MimeType.PDF)], name: "Jordan Lee – Acme Corp" } ); Logger.log("Draft with attachment and CC created."); }

Listing All Existing Drafts

function listDrafts() { var drafts = GmailApp.getDrafts(); drafts.forEach(function(draft) { var msg = draft.getMessage(); Logger.log("To: " + msg.getTo() + " | Subject: " + msg.getSubject()); }); }