A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/apps-script/reference/gmail/gmail-label below:

Class GmailLabel | Apps Script

Class GmailLabel

Stay organized with collections Save and categorize content based on your preferences.

GmailLabel

A user-created label in a user's Gmail account.

Detailed documentation addToThread(thread)

Adds this label to the given thread and forces the thread to refresh (GmailThread.refresh()).

// label the first thread in the inbox with the label MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
label.addToThread(firstThread);
Parameters Name Type Description thread GmailThread The thread to be labeled. Return

GmailLabel — This label, for chaining.

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

See also addToThreads(threads)

Adds this label to the given threads and forces the threads to refresh. You can add labels for up to 100 threads per batch.

// label the first three threads in the inbox with the label MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = GmailApp.getInboxThreads(0, 3);
label.addToThreads(threads);
Parameters Name Type Description threads GmailThread[] An array of threads to be labeled. Return

GmailLabel — This label, for chaining.

Authorization

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

See also deleteLabel()

Deletes this label.

const label = GmailApp.getUserLabelByName('MyLabel');
label.deleteLabel();
Throws

Error — if the label can't be deleted

Authorization

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

See also getId()

Gets the id of this label.

const label = GmailApp.getUserLabelByName('MyLabel');
console.log(label.getId());
Return

String — The id of the label.

Authorization

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

getName()

Gets the name of this label.

const label = GmailApp.getUserLabelByName('MyLabel');
Logger.log(label.getName());  // logs MyLabel
Return

String — The name of the label.

Authorization

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

getThreads()

Gets the threads that are marked with this label.

This calls fail when the size of all threads is too large for the system to handle. Where the thread size is unknown, and potentially very large, please use getThreads(start, max) and specify ranges of the threads to retrieve in each call.

// Log the subject lines of the threads labeled with MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = label.getThreads();
for (let i = 0; i < threads.length; i++) {
  Logger.log(threads[i].getFirstMessageSubject());
}
Return

GmailThread[] — An array of threads marked with this label.

Authorization

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

getThreads(start, max)

Gets a range of threads marked with this label.

// log the subject lines of up to the first 30 threads with the label MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = label.getThreads(0, 30);
for (let i = 0; i < threads.length; i++) {
  Logger.log(threads[i].getFirstMessageSubject());
}
Parameters Name Type Description start Integer The index of the starting thread. max Integer The maximum number of threads to return. Return

GmailThread[] — An array of threads marked with this label.

Authorization

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

getUnreadCount()

Gets the number of unread threads tagged with this label.

// log the number of unread threads labeled with MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
Logger.log(label.getUnreadCount());
Return

Integer — The number of unread labeled threads.

Authorization

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

removeFromThread(thread)

Removes this label from the given thread and forces the thread to refresh.

// remove the label MyLabel from the first thread in the inbox
const label = GmailApp.getUserLabelByName('MyLabel');
const firstThread = GmailApp.getInboxThreads(0, 1)[0];
label.removeFromThread(firstThread);
Parameters Name Type Description thread GmailThread The thread be unlabeled. Return

GmailLabel — This label, for chaining.

Authorization

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

See also removeFromThreads(threads)

Removes this label from the given threads and forces the threads to refresh. You can remove labels for up to 100 threads per batch.

// remove the label MyLabel from the first three threads in the inbox
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = GmailApp.getInboxThreads(0, 3);
label.removeFromThreads(threads);
Parameters Name Type Description threads GmailThread[] An array of threads to be unlabeled. Return

GmailLabel — This label, for chaining.

Authorization

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

See also

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

Last updated 2025-08-04 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-04 UTC."],[[["A `GmailLabel` represents a user-created label within a user's Gmail account, enabling organization and management of emails."],["It provides methods to add or remove labels from threads, delete labels, retrieve label name, access labeled threads, and count unread threads with the label."],["The `addToThreads()` and `removeFromThreads()` methods allow for batch operations on up to 100 threads at a time."],["`getThreads()` method can potentially fail for large thread sizes; use `getThreads(start, max)` for better performance in such scenarios."],["All methods require authorization with the `https://mail.google.com/` scope."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4