자동화 빠른 시작

Google Docs 문서를 만들고 문서 링크를 이메일로 전송하는 간단한 자동화를 빌드하고 실행합니다.

목표

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

기본 요건

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

  • Google 계정 (Google Workspace 계정은 관리자 승인이 필요할 수 있음)
  • 인터넷 액세스가 가능한 웹브라우저

스크립트 설정

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

  1. 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. 메시지가 표시되면 스크립트를 승인합니다. OAuth 동의 화면에 확인되지 않은 앱입니다라는 경고가 표시되면 고급 > {프로젝트 이름}(으)로 이동(안전하지 않음)을 선택하여 계속 진행합니다.

  3. 스크립트 실행이 완료되면 Gmail 받은편지함에서 이메일을 확인합니다.

  4. 이메일을 열고 링크를 클릭하여 내가 만든 문서를 엽니다.

다음 단계