Class GmailLabel

Gmail標籤

使用者在 Gmail 帳戶中建立的標籤。

方法

方法傳回類型簡短說明
addToThread(thread)GmailLabel將這個標籤新增至指定討論串,並強制重新整理討論串 (GmailThread.refresh())。
addToThreads(threads)GmailLabel將這個標籤新增至指定討論串,並強制重新整理討論串。
deleteLabel()void刪除這個標籤。
getId()String取得這個標籤的 ID。
getName()String取得這個標籤的名稱。
getThreads()GmailThread[]取得標示這個標籤的討論串。
getThreads(start, max)GmailThread[]取得標示這個標籤的討論串範圍。
getUnreadCount()Integer取得標示這個標籤的未讀討論串數量。
removeFromThread(thread)GmailLabel從指定執行緒中移除這個標籤,並強制重新整理執行緒。
removeFromThreads(threads)GmailLabel從指定執行緒移除這個標籤,並強制重新整理執行緒。

內容詳盡的說明文件

addToThread(thread)

將這個標籤新增至指定討論串,並強制重新整理討論串 (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);

參數

名稱類型說明
threadGmailThread要加上標籤的討論串。

回攻員

GmailLabel — 這個標籤用於鏈結。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

另請參閱


addToThreads(threads)

將這個標籤新增至指定討論串,並強制重新整理討論串。每個批次最多可為 100 個郵件串新增標籤。

// 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);

參數

名稱類型說明
threadsGmailThread[]要加上標籤的執行緒陣列。

回攻員

GmailLabel — 這個標籤用於鏈結。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

另請參閱


deleteLabel()

刪除這個標籤。

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

擲回

Error - 如果無法刪除標籤

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

另請參閱


getId()

取得這個標籤的 ID。

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

回攻員

String:標籤的 ID。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

getName()

取得這個標籤的名稱。

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

回攻員

String:標籤名稱。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

getThreads()

取得標示這個標籤的討論串。

如果所有執行緒的大小過大,系統無法處理,這類呼叫就會失敗。如果執行緒大小不明,且可能非常大,請使用 getThreads(start, max),並在每次呼叫中指定要擷取的執行緒範圍。

// 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());
}

回攻員

GmailThread[]:標示這個標籤的執行緒陣列。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

getThreads(start, max)

取得標示有這個標籤的討論串範圍。

// 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());
}

參數

名稱類型說明
startInteger起始執行緒的索引。
maxInteger要傳回的執行緒數量上限。

回攻員

GmailThread[]:標示這個標籤的執行緒陣列。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

getUnreadCount()

取得標示這個標籤的未讀討論串數量。

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

回攻員

Integer - 未讀取已加上標籤的討論串數量。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

removeFromThread(thread)

從指定執行緒中移除這個標籤,並強制重新整理執行緒。

// 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);

參數

名稱類型說明
threadGmailThread討論串會取消標籤。

回攻員

GmailLabel — 這個標籤用於鏈結。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

另請參閱


removeFromThreads(threads)

從指定執行緒中移除這個標籤,並強制重新整理執行緒。每個批次最多可移除 100 個討論串的標籤。

// 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);

參數

名稱類型說明
threadsGmailThread[]要取消標籤的討論串陣列。

回攻員

GmailLabel — 這個標籤用於鏈結。

授權

使用這個方法的指令碼需要透過下列一或多個範圍相關 REST API 中的適當範圍授權:

  • https://mail.google.com/

另請參閱