Class GmailDraft

  • GmailDraft represents a user-created draft message in a user's Gmail account.

  • You can perform various actions on a GmailDraft, including deleting, sending, and updating its content.

  • You can retrieve information about a GmailDraft, such as its ID and the underlying GmailMessage it represents.

  • Updating a draft allows you to replace its contents with new recipient, subject, and body information, with options for attachments and HTML body.

GmailDraft

A user-created draft message in a user's Gmail account.

Methods

MethodReturn typeBrief description
deleteDraft()voidDeletes this draft message.
getId()StringGets the ID of this draft message.
getMessage()GmailMessageReturns a GmailMessage representing this draft.
getMessageId()StringReturns the ID of theGmailMessage representing this draft.
send()GmailMessageSends this draft email message.
update(recipient, subject, body)GmailDraftReplaces the contents of this draft message.
update(recipient, subject, body, options)GmailDraftReplaces the contents of this draft message using optional arguments.

Detailed documentation

deleteDraft()

Deletes this draft message.

constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderdraft.deleteDraft();draft.getMessage();// Throws exception.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

getId()

Gets the ID of this draft message.

constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderconstdraftId=draft.getId();constdraftById=GmailApp.getDraft(draftId);Logger.log(draft.getMessage().getSubject()===draftById.getMessage().getSubject(),);

Return

String — the draft ID

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

getMessage()

Returns a GmailMessage representing this draft.

constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderconstmessage=draft.getMessage();Logger.log(message.getSubject());

Return

GmailMessage — the message that represents the contents of this draft

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

getMessageId()

Returns the ID of theGmailMessage representing this draft.

constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderconstmessageId=draft.getMessageId();Logger.log(messageId===draft.getMessage().getId());

Return

String — the message ID

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

send()

Sends this draft email message. The size of the email (including headers) isquota limited.

constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderconstmsg=draft.send();// Send itLogger.log(msg.getDate());// Should be approximately the current timestamp

Return

GmailMessage — the newly sent message

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

update(recipient, subject, body)

Replaces the contents of this draft message. The size of the email (including headers) isquota limited.

// The code below will update a draft email with the current date and time.constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderconstnow=newDate();draft.update('mike@example.com','current time',`The time is:${now.toString()}`,);

Parameters

NameTypeDescription
recipientStringcomma separated list of email addresses
subjectStringsubject of the email (250 characters maximum)
bodyStringbody of the email

Return

GmailDraft — the newly updated draft

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

See also


update(recipient, subject, body, options)

Replaces the contents of this draft message using optional arguments. The email can containplain text or an HTML body. The size of the email (including headers) isquota limited.

// Update a draft email with a file from Google Drive attached as a PDF.constdraft=GmailApp.getDrafts()[0];// The first draft message in the drafts folderconstfile=DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');draft.update('mike@example.com','Attachment example','Please see attached file.',{attachments:[file.getAs(MimeType.PDF)],name:'Automatic Emailer Script',},);

Parameters

NameTypeDescription
recipientStringcomma separated list of email addresses
subjectStringsubject of the email (250 characters maximum)
bodyStringbody of the email
optionsObjecta JavaScript object that specifies advanced parameters, as listed below

Advanced parameters

NameTypeDescription
attachmentsBlobSource[]an array of files to send with the email
bccStringa comma-separated list of email addresses to BCC
ccStringa comma-separated list of email addresses to CC
fromStringthe address that the email should be sent from, which must be one of the values returned byGmailApp.getAliases()
htmlBodyStringif set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optionalinlineImages field in HTML body if you have inlined images for your email
inlineImagesObjecta JavaScript object containing a mapping from image key (String) to image data (BlobSource); this assumes that thehtmlBody parameter is used and contains references to these images in the format<img src="cid:imageKey" />
nameStringthe name of the sender of the email (default: the user's name)
replyToStringan email address to use as the default reply-to address (default: the user's email address)

Return

GmailDraft — the newly updated draft

Authorization

Scripts that use this method require authorization with one or more of the followingscopes or appropriate scopes from therelated REST API:

  • https://mail.google.com/

See also

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.