자동화 빠른 시작

Google Docs 문서를 만들고 문서 링크를 이메일로 보내는 자동화를 빌드하고 실행합니다.

목표

  • 스크립트를 설정합니다.
  • 스크립트를 실행합니다.

기본 요건

이 샘플을 사용하려면 다음과 같은 기본 요건이 필요합니다.

  • Google 계정 (Google Workspace 계정의 경우 관리자 승인이 필요할 수 있음)
  • 인터넷에 액세스할 수 있는 웹브라우저

스크립트 설정

자동화를 빌드하려면 다음 단계를 따르세요.

  1. Google Apps Script 편집기를 열려면 script.google.com으로 이동합니다. script.google.com에 처음 방문하는 경우 대시보드 보기를 클릭합니다.
  2. 새 프로젝트 를 클릭합니다.
  3. 스크립트 편집기에서 코드를 삭제하고 다음 코드를 붙여넣습니다.

    templates/standalone/helloWorld.gs
    /**
     * Creates a Google Doc and sends an email to the current user with a link to the doc.
     */
    function createAndSendDocument() {
      try {
        // Create a new Google Doc named 'Hello, world!'
        const doc = DocumentApp.create("Hello, world!");
    
        // Access the body of the document, then add a paragraph.
        doc
          .getBody()
          .appendParagraph("This document was created by Google Apps Script.");
    
        // Get the URL of the document.
        const url = doc.getUrl();
    
        // Get the email address of the active user - that's you.
        const email = Session.getActiveUser().getEmail();
    
        // Get the name of the document to use as an email subject line.
        const subject = doc.getName();
    
        // Append a new string to the "url" variable to use as an email body.
        const body = `Link to your doc: ${url}`;
    
        // Send yourself an email with a link to the document.
        GmailApp.sendEmail(email, subject, body);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log("Failed with error %s", err.message);
      }
    }
  4. 저장 저장 작업을 나타내는 아이콘을 클릭합니다.

  5. 제목 없는 프로젝트 를 클릭합니다.

  6. 스크립트 이름을 입력하고 이름 바꾸기 를 클릭합니다.

스크립트 실행

스크립트를 실행하려면 다음 단계를 따르세요.

  1. 실행 을 클릭합니다.
  2. 메시지가 표시되면 스크립트를 승인합니다. <<../samples/_snippets/oauth.md>>
  3. 스크립트 실행이 완료되면 Gmail 받은편지함 에서 이메일을 확인합니다.
  4. 이메일을 열고 링크를 클릭하여 만든 문서를 엽니다.

다음 단계