고급 Gmail 서비스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
고급 Gmail 서비스를 통해 Google Apps Script에서
Gmail API를 사용할 수 있습니다. Apps Script의 기본 제공 Gmail 서비스와 마찬가지로 이 API를 사용하면 스크립트에서 Gmail 편지함의 대화목록, 메시지, 라벨을 찾고 수정할 수 있습니다. 대부분의 경우 기본 제공 서비스를 사용하는 것이 더 쉽지만 이 고급 서비스는 몇 가지 추가 기능과 Gmail 콘텐츠에 관한 더 자세한 정보에 대한 액세스를 제공합니다.
이 서비스에 관한 자세한 내용은
Gmail API의
참고 문서를 확인하세요. Apps Script의 모든 고급 서비스와 마찬가지로 고급 Gmail 서비스는 공개 API와 동일한 객체, 메서드, 매개변수를 사용합니다. 자세한 내용은
다음을
참고하세요. 메서드 서명이 결정되는 방식
/** * 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);}}
받은편지함 스니펫 나열
다음 예는 사용자의 받은편지함에 있는 각 스레드와 연결된 텍스트 스니펫을 나열하는 방법을 보여줍니다. 결과의 전체 목록에 액세스하기 위해 페이지 토큰이 사용되는 방식을 확인하세요.
/** * 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){for(constthreadofthreadList.threads){console.log(`Snippet: ${thread.snippet}`);}}pageToken=threadList.nextPageToken;}while(pageToken);}catch(err){console.log(err);}}
최근 기록 나열
다음 예는 최근 활동 내역을 로깅하는 방법을 보여줍니다.
특히 이 예는 사용자가 가장 최근에 보낸 메시지와 연결된 기록 레코드 ID를 복구한 후 그 이후로 변경된 모든 메시지의 메시지 ID를 로깅합니다. 변경된 각 메시지는 기록 레코드에 변경 이벤트가 얼마나 많이 있든 한 번만 로깅됩니다. 결과의 전체 목록에 액세스하기 위해 페이지 토큰이 사용되는 방식을 확인하세요.
/** * 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("No sent threads found.");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){for(constrecordofhistory){for(constmessageofrecord.messages){if(changed.indexOf(message.id)===-1){changed.push(message.id);}}}}pageToken=recordList.nextPageToken;}while(pageToken);for(constidofchanged){console.log("Message Changed: %s",id);}}catch(err){console.log(err);}}
/** * Lists unread messages in the user's inbox using the advanced Gmail service. */functionlistMessages(){// The special value 'me' indicates the authenticated user.constuserId="me";// Define optional parameters for the request.constoptions={maxResults:10,// Limit the number of messages returned.q:"is:unread",// Search for unread messages.};try{// Call the Gmail.Users.Messages.list method.constresponse=Gmail.Users.Messages.list(userId,options);constmessages=response.messages;console.log("Unread Messages:");for(constmessageofmessages){console.log(`- Message ID: ${message.id}`);}}catch(err){// Log any errors to the Apps Script execution log.console.log(`Failed with error: ${err.message}`);}}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2026-05-05(UTC)"],[],[]]