Object reference
Gmail thread
A GmailThread holds one Gmail conversation. Reach threads with GmailApp.search() or label.getThreads(), then call getMessages() or addLabel().
GmailApp.GmailThreadStart here
Get this object first
Get threads from a Gmail label with label.getThreads(), or search your mailbox directly with GmailApp.search(query, start, max).
function showFirstLabeledThreadSubject() {
const label = GmailApp.getUserLabelByName('Save to Drive');
if (!label) throw new Error('Create a Gmail label named Save to Drive first.');
const threads = label.getThreads();
if (!threads.length) return;
Logger.log(threads[0].getFirstMessageSubject());
} Then use it
Common actions
Choose an action, then open its example only when you need the code.
Count the messages in a conversation
This records a count for the first conversation carrying your Save to Drive label.
GmailApp.GmailThreadShow example code
function countFirstLabeledThreadMessages() {
const label = GmailApp.getUserLabelByName('Save to Drive');
if (!label) throw new Error('Create a Gmail label named Save to Drive first.');
const threads = label.getThreads();
if (!threads.length) return;
Logger.log(threads[0].getMessages().length);
} Search recent threads and log subjects
This searches the last 7 days with GmailApp.search() and logs up to 5 thread subjects and message counts without changing any mail.
GmailApp.GmailThreadShow example code
function logRecentThreadSubjects() {
const threads = GmailApp.search('newer_than:7d', 0, 5);
threads.forEach((thread) => {
Logger.log(thread.getFirstMessageSubject() + ' (' + thread.getMessageCount() + ' messages)');
});
} List user labels on a conversation
This reads getLabels() on the first matching thread and logs the label names without adding or removing any labels.
GmailApp.GmailThreadGmailApp.GmailLabelShow example code
function logThreadLabelNames() {
const label = GmailApp.getUserLabelByName('Save to Drive');
if (!label) throw new Error('Create a Gmail label named Save to Drive first.');
const threads = label.getThreads();
if (!threads.length) return;
const labelNames = threads[0].getLabels().map((item) => item.getName());
Logger.log(labelNames.join(', '));
} Technical reference
Exact names and signatures
Generated runtime and signature facts stay separate from the beginner actions above. Open method details only when you need them.
At a glance
- Service
- GmailApp
- Reference symbol
GmailApp.GmailThread- Object
GmailThread- Runtime
- From signature data
Methods and signatures
Browse 30 methods
addLabel
- addLabel(label: GmailApp.GmailLabel): GmailApp.GmailThread
createDraftReply
- createDraftReply(body: string): GmailApp.GmailDraft
- createDraftReply(body: string, options: unknown): GmailApp.GmailDraft
createDraftReplyAll
- createDraftReplyAll(body: string): GmailApp.GmailDraft
- createDraftReplyAll(body: string, options: unknown): GmailApp.GmailDraft
getFirstMessageSubject
- getFirstMessageSubject(): string
getId
- getId(): string
getLabels
- getLabels(): GmailApp.GmailLabel[]
getLastMessageDate
- getLastMessageDate(): Date
getMessageCount
- getMessageCount(): number
getMessages
- getMessages(): GmailApp.GmailMessage[]
getPermalink
- getPermalink(): string
hasStarredMessages
- hasStarredMessages(): boolean
isImportant
- isImportant(): boolean
isInChats
- isInChats(): boolean
isInInbox
- isInInbox(): boolean
isInPriorityInbox
- isInPriorityInbox(): boolean
isInSpam
- isInSpam(): boolean
isInTrash
- isInTrash(): boolean
isUnread
- isUnread(): boolean
markImportant
- markImportant(): GmailApp.GmailThread
markRead
- markRead(): GmailApp.GmailThread
markUnimportant
- markUnimportant(): GmailApp.GmailThread
markUnread
- markUnread(): GmailApp.GmailThread
moveToArchive
- moveToArchive(): GmailApp.GmailThread
moveToInbox
- moveToInbox(): GmailApp.GmailThread
moveToSpam
- moveToSpam(): GmailApp.GmailThread
moveToTrash
- moveToTrash(): GmailApp.GmailThread
refresh
- refresh(): GmailApp.GmailThread
removeLabel
- removeLabel(label: GmailApp.GmailLabel): GmailApp.GmailThread
reply
- reply(body: string): GmailApp.GmailThread
- reply(body: string, options: GmailApp.GmailAdvancedParameters): GmailApp.GmailThread
replyAll
- replyAll(body: string): GmailApp.GmailThread
- replyAll(body: string, options: unknown): GmailApp.GmailThread
Need the whole workflow?
Return to a task guide
Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.
Browse Gmail tasks