Apps Script 빠른 시작

이 도움말에서는 Apps Script를 사용하여 이메일 마크업을 테스트하기 위해 스키마가 포함된 이메일을 자신에게 보내는 방법을 설명합니다.

프로젝트 만들기

script.google.com을 방문합니다. script.google.com에 처음 방문한 경우 정보 페이지로 리디렉션됩니다. 스크립팅 시작을 클릭하여 스크립트 편집기로 이동합니다. 스크립트 편집기에서 빈 프로젝트의 스크립트를 만듭니다.

Code.gs의 코드를 다음으로 바꿉니다.

gmail/markup/Code.gs
/**
 * Send an email with schemas in order to test email markup.
 */
function testSchemas() {
  try {
    const htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();

    MailApp.sendEmail({
      to: Session.getActiveUser().getEmail(),
      subject: 'Test Email markup - ' + new Date(),
      htmlBody: htmlBody
    });
  } catch (err) {
    console.log(err.message);
  }
}

파일 > 새로 만들기 > HTML 파일을 선택하여 새 HTML 파일을 만듭니다. 위 자바스크립트의 매개변수와 일치하도록 파일 이름을 mail_template로 지정합니다. HTML 파일의 콘텐츠를 다음으로 바꿉니다.

gmail/markup/mail_template.html
<!--
 Copyright 2022 Google LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<html>
  <head>
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "EmailMessage",
      "description": "Check this out",
      "potentialAction": {
        "@type": "ViewAction",
        "target": "https://www.youtube.com/watch?v=eH8KwfdkSqU"
      }
    }
    </script>
  </head>
  <body>
    <p>
      This a test for a Go-To action in Gmail.
    </p>
  </body>
</html>

스크립트 테스트

스크립트를 테스트하려면 다음 안내를 따르세요.

  1. 프로젝트를 저장합니다.
  2. Code.gs 탭을 선택합니다.
  3. Select function 드롭다운 메뉴에서 testSchemas 함수가 선택되어 있는지 확인합니다.
  4. Apps Script 개발 환경에서 Run를 클릭합니다.

스크립트를 처음 실행하면 권한을 부여하라는 메시지가 표시되고 그 후에 다시 실행해야 합니다. 스크립트가 실행되면 다음 스크린샷과 같이 받은편지함에서 Go-To Action(이동 작업) 버튼이 있는 직접 보낸 이메일이 있는지 확인합니다.

Apps Script 튜토리얼

스크립트는 어떻게 작동하나요?

testSchemas 함수는 mail_template.html 파일에서 HTML 콘텐츠를 읽고 이 콘텐츠를 현재 인증된 사용자에게 이메일로 전송합니다. Google에 등록하기에서 설명한 대로 자신에게 보내는 모든 스키마가 Gmail에 표시되므로 테스트 목적으로 스크립트에서 보낸 이메일을 사용하여 등록 요구사항을 무시할 수 있습니다.