Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Dịch vụ Gmail nâng cao cho phép bạn sử dụng API Gmail trong Apps Script. Tương tự như dịch vụ Gmail tích hợp của Apps Script, API này cho phép các tập lệnh tìm và sửa đổi chuỗi thư, thư và nhãn trong hộp thư Gmail. Trong hầu hết các trường hợp, dịch vụ tích hợp sẵn sẽ dễ sử dụng hơn, nhưng dịch vụ nâng cao này cung cấp một số tính năng bổ sung và quyền truy cập vào thông tin chi tiết hơn về nội dung trong Gmail.
Tài liệu tham khảo
Để biết thông tin chi tiết về dịch vụ này, hãy xem tài liệu tham khảo cho API Gmail.
Giống như tất cả các dịch vụ nâng cao trong Apps Script, dịch vụ Gmail nâng cao sử dụng cùng các đối tượng, phương thức và tham số như API công khai. Để biết thêm thông tin, hãy xem phần Cách xác định chữ ký phương thức.
/** * Lists the user's labels, including name, type, * ID and visibility information. */functionlistLabelInfo(){try{constresponse=Gmail.Users.Labels.list('me');for(leti=0;i < response.labels.length;i++){constlabel=response.labels[i];console.log(JSON.stringify(label));}}catch(err){console.log(err);}}
Liệt kê các đoạn mã trong hộp thư đến
Ví dụ sau đây minh hoạ cách liệt kê các đoạn văn bản liên kết với từng chuỗi thư trong Hộp thư đến của người dùng. Lưu ý việc sử dụng mã thông báo trang để truy cập vào danh sách đầy đủ các kết quả.
/** * Lists, for each thread in the user's Inbox, a * snippet associated with that thread. */functionlistInboxSnippets(){try{letpageToken;do{constthreadList=Gmail.Users.Threads.list('me',{q:'label:inbox',pageToken:pageToken});if(threadList.threads && threadList.threads.length > 0){threadList.threads.forEach(function(thread){console.log('Snippet:%s',thread.snippet);});}pageToken=threadList.nextPageToken;}while(pageToken);}catch(err){console.log(err);}}
Liệt kê nhật ký gần đây
Ví dụ sau đây minh hoạ cách ghi nhật ký hoạt động gần đây.
Cụ thể, ví dụ này khôi phục mã bản ghi nhật ký liên kết với thông báo mà người dùng đã gửi gần đây nhất, sau đó ghi lại mã thông báo của mọi thông báo đã thay đổi kể từ thời điểm đó. Mỗi thông báo đã thay đổi chỉ được ghi lại một lần, bất kể có bao nhiêu sự kiện thay đổi trong bản ghi nhật ký. Lưu ý việc sử dụng mã thông báo trang để truy cập vào danh sách đầy đủ kết quả.
/** * Gets a history record ID associated with the most * recently sent message, then logs all the message IDs * that have changed since that message was sent. */functionlogRecentHistory(){try{// Get the history ID associated with the most recent// sent message.constsent=Gmail.Users.Threads.list('me',{q:'label:sent',maxResults:1});if(!sent.threads||!sent.threads[0]){console.log('Nosentthreadsfound.');return;}consthistoryId=sent.threads[0].historyId;// Log the ID of each message changed since the most// recent message was sent.letpageToken;constchanged=[];do{constrecordList=Gmail.Users.History.list('me',{startHistoryId:historyId,pageToken:pageToken});consthistory=recordList.history;if(history && history.length > 0){history.forEach(function(record){record.messages.forEach(function(message){if(changed.indexOf(message.id)===-1){changed.push(message.id);}});});}pageToken=recordList.nextPageToken;}while(pageToken);changed.forEach(function(id){console.log('MessageChanged:%s',id);});}catch(err){console.log(err);}}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-06-21 UTC."],[[["The Advanced Gmail service in Apps Script lets you use the Gmail API to interact with your mailbox, offering more features than the built-in service."],["This advanced service requires enabling before use and provides access to detailed information about threads, messages, and labels."],["You can utilize the provided sample code snippets to list label information, inbox snippets, and recent history within your Gmail account."],["The Gmail API might limit data returned in list requests for performance, requiring follow-up 'get' requests for detailed information."],["For comprehensive details, refer to the reference documentation, support guide, and sample code on GitHub."]]],[]]