/** * Send an email with schemas in order to test email markup. */functiontestSchemas(){try{consthtmlBody=HtmlService.createHtmlOutputFromFile("mail_template").getContent();MailApp.sendEmail({to:Session.getActiveUser().getEmail(),subject:`Test Email markup - ${newDate()}`,htmlBody:htmlBody,});}catch(err){console.log(err.message);}}
依序選取「File」>「New」>「Html file」,即可建立新的 HTML 檔案。將檔案命名為 mail_template,與上述 JavaScript 中的參數相符。將 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>
testSchemas 函式會從名為 mail_template.html 的檔案讀取 HTML 內容,並以電子郵件的形式將該內容傳送給目前已通過驗證的使用者。如「向 Google 註冊」一文所述,您傳送給自己的所有結構化資料都會顯示在 Gmail 中,因此您可以使用指令碼傳送的電子郵件,在測試時忽略註冊規定。