

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 管理電子郵件範本
<a name="send-personalized-email-manage-templates"></a>

除了[建立電子郵件範本](send-personalized-email-api.md)之外，您也可以使用 Amazon SES v2 API 來更新或刪除現有的範本、列出所有現有的範本，或檢視範本的內容。

本節包含使用 AWS CLI 執行與 SES 範本相關任務的程序。

**注意**  
本節中的程序假設您已安裝並設定 AWS CLI。如需安裝和設定 的詳細資訊 AWS CLI，請參閱 [AWS Command Line Interface 使用者指南](https://docs.aws.amazon.com/cli/latest/userguide/)。

## 檢視電子郵件範本清單
<a name="send-personalized-email-manage-templates-list"></a>

您可以使用 [`ListEmailTemplate`](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_ListEmailTemplate.html) SES v2 API 操作來檢視所有現有電子郵件範本的清單。

**檢視電子郵件範本清單**
+ 在命令列中輸入以下命令：

  ```
  aws sesv2 list-email-templates
  ```

  如果目前區域中的 SES 帳戶中已有電子郵件範本，此命令會傳回類似下列範例的回應：

  ```
  {
      "TemplatesMetadata": [
          {
              "Name": "SpecialOffers",
              "CreatedTimestamp": "2020-08-05T16:04:12.640Z"
          },
          {
              "Name": "NewsAndUpdates",
              "CreatedTimestamp": "2019-10-03T20:03:34.574Z"
          }
      ]
  }
  ```

  如果您尚未建立範本，命令會傳回不含成員的 `TemplatesMetadata` 物件。

## 檢視特定電子郵件範本的內容
<a name="send-personalized-email-manage-templates-get"></a>

您可以使用 [`GetEmailTemplate`](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailTemplate.html) SES v2 API 操作來檢視特定電子郵件範本的內容。

**檢視電子郵件範本的內容**
+ 在命令列中輸入以下命令：

  ```
  aws sesv2 get-email-template --template-name {{MyTemplate}}
  ```

  在上述命令中，以您要檢視的範本名稱取代 {{MyTemplate}}。

  如果您提供的範本名稱符合 SES 帳戶中存在的範本，此命令會傳回類似下列範例的回應：

  ```
  {
      "Template": {
          "TemplateName": "TestMessage",
          "SubjectPart": "Amazon SES Test Message",
          "TextPart": "Hello! This is the text part of the message.",
          "HtmlPart": "<html>\n<body>\n<h2>Hello!</h2>\n<p>This is the HTML part of the message.</p></body>\n</html>"
      }
  }
  ```

  如果您提供的範本名稱與 SES 帳戶中存在的範本不符，命令會傳回`NotFoundException`錯誤。

## 刪除電子郵件範本
<a name="send-personalized-email-manage-templates-delete"></a>

您可以使用 [`DeleteEmailTemplate`](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_DeleteEmailTemplate.html) SES v2 API 操作來刪除特定電子郵件範本。

**刪除電子郵件範本**
+ 在命令列中輸入以下命令：

  ```
  aws sesv2 delete-email-template --template-name {{MyTemplate}}
  ```

  在先前的命令中，以您想要刪除的範本名稱取代 {{MyTemplate}}。

  此命令不會提供任何輸出。您可以使用 [GetTemplate](#send-personalized-email-manage-templates-get) 作業確認範本已刪除。

## 更新電子郵件範本
<a name="send-personalized-email-manage-templates-update"></a>

您可以使用 [`UpdateEmailTemplate`](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_UpdateEmailTemplate.html) SES v2 API 操作來更新現有的電子郵件範本。例如，如果您想要變更電子郵件範本的主旨行，或者您需要修改郵件本身的內文，這項作業很實用。

**更新電子郵件範本**

1. 在命令列上輸入下列命令，使用 `GetEmailTemplate` 命令來擷取現有範本：

   ```
   aws sesv2 get-email-template --template-name {{MyTemplate}}
   ```

   在上述命令中，以您要更新的範本名稱取代 {{MyTemplate}}。

   如果您提供的範本名稱符合 SES 帳戶中存在的範本，此命令會傳回類似下列範例的回應：

   ```
   {
       "Template": {
           "TemplateName": "TestMessage",
           "SubjectPart": "Amazon SES Test Message",
           "TextPart": "Hello! This is the text part of the message.",
           "HtmlPart": "<html>\n<body>\n<h2>Hello!</h2>\n<p>This is the HTML part of the message.</p></body>\n</html>"
       }
   }
   ```

1. 在文字編輯器中，建立新檔案。將先前命令的輸出貼到檔案中。

1. 可視需要修改範本。您省略的任何行都會從範本中移除。例如，如果您只想更改範本的 `SubjectPart`，仍然需要包含 `TextPart` 和 `HtmlPart` 屬性。

   完成後，請將檔案儲存為 `update_template.json`。

1. 在命令列中輸入以下命令：

   ```
   aws sesv2 update-email-template --cli-input-json file://{{path/to/update_template.json}}
   ```

   在上述命令中，以您在上一個步驟中所建立 `update_template.json` 檔案的完整路徑取代 {{path/to/update\_template.json}}。

   如果範本成功更新，此命令不會提供任何輸出。您可以使用 [`GetEmailTemplate`](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailTemplate.html)操作來驗證範本是否已更新。

   如果您指定的範本不存在，此命令會傳回 `TemplateDoesNotExist` 錯誤。如果範本不包含 `TextPart` 或 `HtmlPart` 屬性 (或兩者皆不含)，此命令會傳回 `InvalidParameterValue` 錯誤。