

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 템플릿을 사용하여 Amazon SES API를 통해 맞춤형 이메일 전송
<a name="send-personalized-email-api"></a>

Amazon SES에서는 *저장된 템플릿*을 사용하거나 *인라인 템플릿*을 사용하여 템플릿 이메일을 보낼 수 있습니다.
+ **저장된 템플릿** - Amazon SES v2 API의 `CreateEmailTemplate` 작업을 사용하여 SES에서 생성 및 저장된 [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Template.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Template.html) 리소스를 나타냅니다. 템플릿에는 작성된 콘텐츠와 일치하는 변수(자리 표시자)가 포함된 이메일의 제목과 본문이 포함되어 있습니다. 저장된 템플릿의 이름과 템플릿의 자리 표시자 변수에 대한 동적 데이터는 `SendEmail` 또는 `SendBulkEmail` v2 API 작업을 직접적으로 호출할 때 제공됩니다.

  *저장된 템플릿*은 쉽게 재사용할 수 있으며 유사한 유형의 이메일을 보낼 때 시간과 노력을 절약해 줍니다. 처음부터 각 이메일을 생성하는 대신 기본 구조와 설계를 한 번만 생성한 다음 템플릿 내의 동적 콘텐츠를 업데이트하면 됩니다.
+ **인라인 템플릿** - `Template` 리소스를 사용하지 않고, 대신 작성된 콘텐츠에 변수(자리 표시자)를 인라인 형태로 포함한 이메일의 제목과 본문을 제공합니다. 이러한 자리 표시자 변수의 값은 `SendEmail` 또는 `SendBulkEmail` v2 API 작업을 직접적으로 호출할 때 함께 제공합니다.

  *인라인 템플릿*은 SES 계정에서 템플릿 리소스를 관리할 필요가 없어 대량 이메일 전송 프로세스를 간소화하고 애플리케이션 로직 내에 템플릿 콘텐츠를 직접 포함할 수 있으므로 통합 프로세스를 간소화합니다. 당 20,000개 템플릿 제한에 포함되지 않습니다 AWS 리전.

*저장된 템플릿*을 사용할 때는 다음 제한이 적용됩니다.
+ 각각 최대 20,000개의 이메일 템플릿을 생성할 수 있습니다 AWS 리전.
+ 각 템플릿의 최대 크기는 텍스트 부분과 HTML 부분을 포함하여 500KB입니다.

*인라인 템플릿*을 사용할 때는 다음 제한이 적용됩니다.
+ 각 입력 JSON 파일의 크기는 텍스트 부분과 HTML 부분을 모두 포함하여 최대 1MB일 수 있습니다.

다음은 *저장된 템플릿*과 *인라인 템플릿* 모두에 적용됩니다.
+ 사용할 수 있는 대체 변수 수에는 제한이 없습니다.
+ 각 `SendBulkEmail` 작업에 대한 직접 호출에서 최대 50개의 대상 객체에 이메일을 보낼 수 있습니다. [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html) 객체에는 **ToAddresses**, **CcAddresses** 및 **BccAddresses**에 정의된 여러 수신자가 포함될 수 있습니다. 단일 v2 API 직접 호출에서 연락할 수 있는 대상 수는 계정의 최대 전송 속도에 의해 제한될 수 있습니다. 자세한 내용은 [Amazon SES 발신 한도 관리](manage-sending-quotas.md) 단원을 참조하십시오.

이 장에는 *저장된 템플릿*과 *인라인 템플릿*을 모두 사용하는 예제가 포함된 절차가 포함되어 있습니다.

**참고**  
이 섹션의 절차는 또한 AWS CLI을(를) 이미 설치하여 구성한 상태를 전제로 설명합니다. 설치 및 구성에 대한 자세한 내용은 [AWS Command Line Interface 사용 설명서를](https://docs.aws.amazon.com/cli/latest/userguide/) AWS CLI참조하세요.

## (선택 사항) 1부: 렌더링 오류 이벤트 알림 설정
<a name="send-personalized-email-set-up-notifications"></a>

 잘못된 맞춤형 콘텐츠가 포함된 이메일을 전송하는 경우 Amazon SES에서 메시지를 허용할 수는 있지만 전달할 수 없게 됩니다. 따라서 맞춤형 이메일을 전송하려면 Amazon SNS를 통해 렌더링 오류 이벤트 알림을 전송하도록 SES를 구성해야 합니다. 렌더링 오류 이벤트 알림을 수신할 때 어떤 메시지에 잘못된 콘텐츠가 있는지 식별하고, 문제를 해결한 다음 메시지를 다시 전송할 수 있습니다.

이 섹션의 절차는 선택 사항이지만 강력히 권장됩니다.

**렌더링 오류 이벤트 알림을 구성하려면**

1. Amazon SNS 주제를 생성합니다. 절차는 *Amazon Simple Notification Service 개발자 가이드*의 [주제 생성](https://docs.aws.amazon.com/sns/latest/dg/sns-create-subscribe-endpoint-to-topic.html)을 참조하세요.

1. Amazon SNS 주제를 구독하세요. 예를 들어 렌더링 오류 알림을 이메일로 수신하고자 하는 경우 이메일 엔드포인트(이메일 주소)를 주제에 구독시킵니다.

   자세한 내용은 *Amazon Simple Notification Service 개발자 가이드*의 [주제 구독](https://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html)을 참조하세요.

1. [이벤트 게시에 필요한 Amazon SNS 이벤트 대상 설정](event-publishing-add-event-destination-sns.md)의 절차를 완료하여 구성 세트를 설정해 렌더링 오류 이벤트를 Amazon SNS 주제에 게시합니다.

## (선택 사항) 2부: 이메일 템플릿 생성
<a name="send-personalized-email-create-template"></a>

*저장된 템플릿*을 사용하려는 경우 이 섹션에서는 [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_CreateEmailTemplate.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_CreateEmailTemplate.html) SES v2 API 작업을 사용하여 템플릿을 생성하는 방법을 보여 줍니다. *인라인 템플릿*을 사용하려면 이 단계를 건너뛸 수 있습니다.

이 절차는 AWS CLI를 이미 설치하여 구성한 상태를 전제로 설명합니다. 설치 및 구성에 대한 자세한 내용은 [AWS Command Line Interface 사용 설명서를](https://docs.aws.amazon.com/cli/latest/userguide/) AWS CLI참조하세요.

**템플릿을 생성하려면**

1. 텍스트 편집기에서 새 파일을 생성하고 필요에 따라 사용자 지정하여 다음 코드를 붙여 넣습니다.

   ```
   {
       "TemplateName": "MyTemplate",
       "TemplateContent": {
           "Subject": "Greetings, {{name}}!",
           "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.",
           "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>"
       }
   }
   ```

   이 코드는 다음 속성을 포함하고 있습니다.
   + **TemplateName** - `Template` 리소스의 이름입니다. 이메일을 보낼 때 이 이름을 참조합니다.
   + **TemplateContent** - 다음 속성을 위한 컨테이너입니다.
     + **제목** - 이메일의 제목입니다. 이 속성에는 대체 태그가 포함될 수 있습니다. 이 태그는 `{{tagname}}` 형식을 사용합니다. 이메일을 보낼 때 각 대상에 대해 `tagname`의 값을 지정할 수 있습니다.
     + **Html** – 이메일의 HTML 본문입니다. 이 속성에는 대체 태그가 포함될 수 있습니다. 이전 예에는 `{{name}}` 및 `{{favoriteanimal}}`이라는 두 가지 태그가 포함됩니다.
     + **Text** – 이메일의 텍스트 본문입니다. 이메일 클라이언트가 HTML 콘텐츠를 표시하지 않는 수신자는 이 이메일 버전을 볼 수 있습니다. 이 속성에는 대체 태그도 포함될 수 있습니다.

1. 위의 예를 필요에 맞게 사용자 지정한 다음 파일을 *mytemplate.json*으로 저장합니다.

1. 명령줄에 다음 명령을 입력하여 [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_CreateEmailTemplate.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_CreateEmailTemplate.html) v2 API 작업을 통해 새 템플릿을 생성합니다.

   ```
   aws sesv2 create-email-template --cli-input-json file://mytemplate.json
   ```

## 3부: 맞춤형 이메일 보내기
<a name="send-personalized-email-api-operations"></a>

다음 두 가지 SES v2 API 작업을 사용하여 *저장된 템플릿* 또는 *인라인 템플릿*을 사용하여 이메일을 보낼 수 있습니다.
+ [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html) 작업은 사용자 지정 이메일을 단일 대상 객체로 보내는 데 유용합니다. v2 API [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html) 객체에는 *ToAddresses*, *CcAddresses* 및 *BccAddresses* 속성이 포함될 수 있습니다. 이러한 주소는 모든 조합으로 사용할 수 있으며 동일한 이메일을 수신할 하나 이상의 이메일 주소를 포함할 수 있습니다.
+ [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html) 작업은 v2 API에 대한 단일 직접 호출로 여러 대상 객체에 고유의 이메일을 보내는 데 유용합니다.

이 섹션에서는를 사용하여 이러한 AWS CLI 두 전송 작업을 모두 사용하여 템플릿이 지정된 이메일을 보내는 방법의 예를 제공합니다.

### 단일 대상 객체에 템플릿 이메일 전송
<a name="send-templated-email-single-destination"></a>

[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html) 작업을 사용하여 단일 대상 객체에 정의된 하나 이상의 수신자에게 이메일을 보낼 수 있습니다. [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html) 객체의 모든 수신자는 동일한 이메일을 수신합니다.

**단일 대상 객체로 템플릿 이메일을 전송하려면**

1. *저장된 템플릿*을 사용할지 *인라인 템플릿*을 사용할지에 따라 텍스트 편집기에 붙여넣을 각 코드 예제를 선택하여 필요에 따라 사용자 지정합니다.

------
#### [ Stored template code example ]

   이전 단계인 *MyTemplate*에서 생성한 템플릿은 `TemplateName` 파라미터의 값으로 참조됩니다.

   ```
   {
       "FromEmailAddress": "Mary Major <mary.major@example.com>",
       "Destination": {
           "ToAddresses": [
               "alejandro.rosalez@example.com", "jimmy.jet@example.com"
           ]
       },
       "Content": {
           "Template": {
               "TemplateName": "MyTemplate",
               "TemplateData": "{ \"name\":\"Alejandro\", \"favoriteanimal\": \"alligator\" }"
           }
       },
       "ConfigurationSetName": "ConfigSet"
   }
   ```

   이 코드는 다음 속성을 포함하고 있습니다.
   + **FromEmailAddress** - 발신자의 이메일 주소입니다.
   + **대상** - *ToAddresses*, *CcAddresses* 및 *BccAddresses* 속성에 정의된 이메일 수신자가 포함된 객체입니다. 이러한 주소는 모든 조합으로 사용할 수 있으며 동일한 이메일을 수신할 하나 이상의 이메일 주소를 포함할 수 있습니다.
   + **TemplateName** – 이메일에 적용할 `Template` 리소스의 이름입니다.
   + **TemplateData** – 키-값 페어를 포함하는 이스케이프된 JSON 문자열입니다. 키는 저장된 템플릿(예: `{{name}}`)의 `TemplateContent` 속성에 정의된 변수에 해당합니다. 값은 변수를 대체하는 콘텐츠를 나타냅니다.
   + **ConfigurationSetName** – 이메일 전송 시 사용할 구성 세트의 이름입니다.
**참고**  
렌더링 오류 이벤트를 Amazon SNS에 게시하도록 구성된 구성 세트를 사용하는 것이 좋습니다. 자세한 내용은 [(선택 사항) 1부: 렌더링 오류 이벤트 알림 설정](#send-personalized-email-set-up-notifications) 단원을 참조하십시오.

------
#### [ Inline template code example ]

   `TemplateContent` 속성(일반적으로 *저장된 템플릿*에 정의됨)은 이를 *인라인* 템플릿으로 만드는 `TemplateData` 속성과 함께 *인라인*으로 정의됩니다.

   ```
   {
       "FromEmailAddress": "Mary Major <mary.major@example.com>",
       "Destination": {
           "ToAddresses": [
               "alejandro.rosalez@example.com", "jimmy.jet@example.com"
           ]
       },
       "Content": {
           "Template": {
               "TemplateContent": {
                   "Subject": "Greetings, {{name}}!",
                   "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.",
                   "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>"
               },
               "TemplateData": "{ \"name\":\"Alejandro\", \"favoriteanimal\": \"alligator\" }"
           }
       },
       "ConfigurationSetName": "ConfigSet"
   }
   ```

   이 코드는 다음 속성을 포함하고 있습니다.
   + **FromEmailAddress** - 발신자의 이메일 주소입니다.
   + **대상** - *ToAddresses*, *CcAddresses* 및 *BccAddresses* 속성에 정의된 이메일 수신자가 포함된 객체입니다. 이러한 주소는 모든 조합으로 사용할 수 있으며 동일한 이메일을 수신할 하나 이상의 이메일 주소를 포함할 수 있습니다.
   + **TemplateContent** - 다음 속성을 위한 컨테이너입니다.
     + **제목** - 이메일의 제목입니다. 이 속성에는 대체 태그가 포함될 수 있습니다. 이 태그는 `{{tagname}}` 형식을 사용합니다. 이메일을 보낼 때 각 대상에 대해 `tagname`의 값을 지정할 수 있습니다.
     + **Html** – 이메일의 HTML 본문입니다. 이 속성에는 대체 태그가 포함될 수 있습니다. 이전 예에는 `{{name}}` 및 `{{favoriteanimal}}`이라는 두 가지 태그가 포함됩니다.
     + **Text** – 이메일의 텍스트 본문입니다. 이메일 클라이언트가 HTML 콘텐츠를 표시하지 않는 수신자는 이 이메일 버전을 볼 수 있습니다. 이 속성에는 대체 태그도 포함될 수 있습니다.
   + **TemplateData** – 키-값 페어를 포함하는 이스케이프된 JSON 문자열입니다. 키는 `{{name}}`과 같이 이 파일의 `TemplateContent` 속성에 정의된 변수에 해당합니다. 값은 변수를 대체하는 콘텐츠를 나타냅니다.
   + **ConfigurationSetName** – 이메일 전송 시 사용할 구성 세트의 이름입니다.
**참고**  
렌더링 오류 이벤트를 Amazon SNS에 게시하도록 구성된 구성 세트를 사용하는 것이 좋습니다. 자세한 내용은 [(선택 사항) 1부: 렌더링 오류 이벤트 알림 설정](#send-personalized-email-set-up-notifications) 단원을 참조하십시오.

------

1. 위의 예를 필요에 맞게 사용자 지정한 다음 파일을 *myemail.json*으로 저장합니다.

1. 명령줄에 v2 API 명령을 입력하여 이메일을 보냅니다.

   ```
   aws sesv2 send-email --cli-input-json file://myemail.json
   ```

### 여러 대상 객체에 템플릿 이메일 전송
<a name="send-templated-email-multiple-destinations"></a>

[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html) 작업을 사용하여 SES v2 API에 대한 단일 직접 호출에서 여러 대상 객체로 이메일을 전송할 수 있습니다. SES는 각 [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Destination.html) 객체의 수신자 또는 수신자들에게 고유한 이메일을 전송합니다.

**여러 대상 객체에 템플릿 이메일 전송**

1. *저장된 템플릿*을 사용할지 *인라인 템플릿*을 사용할지에 따라 텍스트 편집기에 붙여넣을 각 코드 예제를 선택하여 필요에 따라 사용자 지정합니다.

------
#### [ Stored template code example ]

   이전 단계인 *MyTemplate*에서 생성한 템플릿은 `TemplateName` 파라미터의 값으로 참조됩니다.

   ```
   {
       "FromEmailAddress": "Mary Major <mary.major@example.com>",
       "DefaultContent": {
           "Template": {
               "TemplateName": "MyTemplate",
               "TemplateData": "{ \"name\":\"friend\", \"favoriteanimal\":\"unknown\" }"
           }
       },
       "BulkEmailEntries": [
           {
               "Destination": {
                   "ToAddresses": [
                       "anaya.iyengar@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{ \"name\":\"Anaya\", \"favoriteanimal\":\"angelfish\" }"
                   }
               }
           },
           {
               "Destination": {
                   "ToAddresses": [
                       "liu.jie@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{ \"name\":\"Liu\", \"favoriteanimal\":\"lion\" }"
                   }
               }
           },
           {
               "Destination": {
                   "ToAddresses": [
                       "shirley.rodriguez@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{ \"name\":\"Shirley\", \"favoriteanimal\":\"shark\" }"
                   }
               }
           },
           {
               "Destination": {
                   "ToAddresses": [
                       "richard.roe@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{}"
                   }
               }
           }
       ],
       "ConfigurationSetName": "ConfigSet"
   }
   ```

   이 코드는 다음 속성을 포함하고 있습니다.
   + **FromEmailAddress** - 발신자의 이메일 주소입니다.
   + **DefaultContent** - `TemplateName` 및 `TemplateData` 객체를 포함하는 JSON 객체입니다.
   + **TemplateName** – 이메일에 적용할 `Template` 리소스의 이름입니다.
   + **TemplateData** - `ReplacementEmailContent` 객체의 `ReplacementTemplateData` 속성에 빈 JSON 객체(`{}`)가 포함된 경우 사용할 키-값 페어를 포함합니다.
   + **BulkEmailEntries** - 하나 이상의 `Destination` 객체를 포함하는 배열입니다.
   + **대상** - *ToAddresses*, *CcAddresses* 및 *BccAddresses* 속성에 정의된 이메일 수신자가 포함된 객체입니다. 이러한 주소는 모든 조합으로 사용할 수 있으며 동일한 이메일을 수신할 하나 이상의 이메일 주소를 포함할 수 있습니다.
   + **ReplacementTemplateData** – 키-값 페어를 포함하는 이스케이프된 JSON 문자열입니다. 키는 템플릿의 변수에 해당합니다(예: `{{name}}`). 값은 이메일의 변수를 대체하는 콘텐츠를 나타냅니다. (여기서 JSON 문자열이 비어 있는 경우(`{}`) `DefaultContent` 객체 내의 `TemplateData` 속성에 정의된 키-값 페어가 사용됩니다.)
   + **ConfigurationSetName** – 이메일 전송 시 사용할 구성 세트의 이름입니다.
**참고**  
렌더링 오류 이벤트를 Amazon SNS에 게시하도록 구성된 구성 세트를 사용하는 것이 좋습니다. 자세한 내용은 [(선택 사항) 1부: 렌더링 오류 이벤트 알림 설정](#send-personalized-email-set-up-notifications) 단원을 참조하십시오.

------
#### [ Inline template code example ]

   `TemplateContent` 속성(일반적으로 *저장된 템플릿*에 정의됨)은 이를 *인라인* 템플릿으로 만드는 `TemplateData` 속성과 함께 *인라인*으로 정의됩니다.

   ```
   {
       "FromEmailAddress": "Mary Major <mary.major@example.com>",
       "DefaultContent": {
           "Template": {
               "TemplateContent": {
                   "Subject": "Greetings, {{name}}!",
                   "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.",
                   "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>"
               },
               "TemplateData": "{ \"name\":\"friend\", \"favoriteanimal\":\"unknown\" }"
           }
       },
       "BulkEmailEntries": [
           {
               "Destination": {
                   "ToAddresses": [
                       "anaya.iyengar@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{ \"name\":\"Anaya\", \"favoriteanimal\":\"angelfish\" }"
                   }
               }
           },
           {
               "Destination": {
                   "ToAddresses": [
                       "liu.jie@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{ \"name\":\"Liu\", \"favoriteanimal\":\"lion\" }"
                   }
               }
           },
           {
               "Destination": {
                   "ToAddresses": [
                       "shirley.rodriguez@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{ \"name\":\"Shirley\", \"favoriteanimal\":\"shark\" }"
                   }
               }
           },
           {
               "Destination": {
                   "ToAddresses": [
                       "richard.roe@example.com"
                   ]
               },
               "ReplacementEmailContent": {
                   "ReplacementTemplate": {
                       "ReplacementTemplateData": "{}"
                   }
               }
           }
       ],
       "ConfigurationSetName": "ConfigSet"
   }
   ```

   이 코드는 다음 속성을 포함하고 있습니다.
   + **FromEmailAddress** - 발신자의 이메일 주소입니다.
   + **DefaultContent** - `TemplateContent` 및 `TemplateData` 객체를 포함하는 JSON 객체입니다.
   + **TemplateContent** - 다음 속성을 위한 컨테이너입니다.
     + **제목** - 이메일의 제목입니다. 이 속성에는 대체 태그가 포함될 수 있습니다. 이 태그는 `{{tagname}}` 형식을 사용합니다. 이메일을 보낼 때 각 대상에 대해 `tagname`의 값을 지정할 수 있습니다.
     + **Html** – 이메일의 HTML 본문입니다. 이 속성에는 대체 태그가 포함될 수 있습니다. 이전 예에는 `{{name}}` 및 `{{favoriteanimal}}`이라는 두 가지 태그가 포함됩니다.
     + **Text** – 이메일의 텍스트 본문입니다. 이메일 클라이언트가 HTML 콘텐츠를 표시하지 않는 수신자는 이 이메일 버전을 볼 수 있습니다. 이 속성에는 대체 태그도 포함될 수 있습니다.
   + **TemplateData** - `ReplacementEmailContent` 객체의 `ReplacementTemplateData` 속성에 빈 JSON 객체(`{}`)가 포함된 경우 사용할 키-값 페어를 포함합니다.
   + **BulkEmailEntries** - 하나 이상의 `Destination` 객체를 포함하는 배열입니다.
   + **대상** - *ToAddresses*, *CcAddresses* 및 *BccAddresses* 속성에 정의된 이메일 수신자가 포함된 객체입니다. 이러한 주소는 모든 조합으로 사용할 수 있으며 동일한 이메일을 수신할 하나 이상의 이메일 주소를 포함할 수 있습니다.
   + **ReplacementTemplateData** – 키-값 페어를 포함하는 이스케이프된 JSON 문자열입니다. 키는 `{{name}}`과 같이 이 파일의 `TemplateContent` 속성에 정의된 변수에 해당합니다. 값은 이메일의 변수를 대체하는 콘텐츠를 나타냅니다. (여기서 JSON 문자열이 비어 있는 경우(`{}`) `DefaultContent` 객체 내의 `TemplateData` 속성에 정의된 키-값 페어가 사용됩니다.)
   + **ConfigurationSetName** – 이메일 전송 시 사용할 구성 세트의 이름입니다.
**참고**  
렌더링 오류 이벤트를 Amazon SNS에 게시하도록 구성된 구성 세트를 사용하는 것이 좋습니다. 자세한 내용은 [(선택 사항) 1부: 렌더링 오류 이벤트 알림 설정](#send-personalized-email-set-up-notifications) 단원을 참조하십시오.

------

1. 이전 단계의 코드의 값을 변경하여 사용자의 요구 사항을 충족시킨 다음 *mybulkemail.json* 파일로 저장합니다.

1. 명령줄에 v2 API 명령을 입력하여 대량 이메일을 보냅니다.

   ```
   aws sesv2 send-bulk-email --cli-input-json file://mybulkemail.json
   ```

# 고급 이메일 맞춤 설정
<a name="send-personalized-email-advanced"></a>

 *저장된 템플릿*을 사용하는 경우, 즉 SES v2 API와 함께 `CreateEmailTemplate` 작업을 사용하여 Amazon SES에서 [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Template.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_Template.html) 리소스를 생성한 경우, 핸들바 시스템을 활용하여 중첩 속성, 배열 반복, 기본 조건문, 인라인 부분 생성과 같은 고급 기능을 포함하는 템플릿을 생성할 수 있습니다. 이 섹션에서는 이러한 기능의 예를 제공합니다.

Handlebars에는 이 섹션에 설명되어 있는 기능 외의 추가 기능이 포함됩니다. 자세한 내용은 [handlebarsjs.com](http://handlebarsjs.com)에서 [Built-In Helpers](https://handlebarsjs.com/guide/builtin-helpers.html)를 참조하세요.

**참고**  
SES는 메시지의 HTML 템플릿을 렌더링할 때 HTML 콘텐츠를 이스케이프하지 않습니다. 즉, 연락처 양식과 같이 사용자 입력 데이터를 포함하는 경우 클라이언트 측에서 이스케이프해야 합니다.

**Topics**
+ [중첩 속성 분석](#send-personalized-email-advanced-nested)
+ [목록 살펴보기](#send-personalized-email-advanced-iterating)
+ [기본 조건문 사용](#send-personalized-email-advanced-conditionals)
+ [인라인 부분 생성](#send-personalized-email-advanced-inline-partials)

## 중첩 속성 분석
<a name="send-personalized-email-advanced-nested"></a>

Handlebars에는 복잡한 고객 데이터를 쉽게 구성할 수 있는 중첩 경로 지원이 포함되고 이메일 템플릿의 그 데이터를 참조합니다.

예를 들어 수신자 데이터를 여러 일반 범주로 조직할 수 있습니다. 각 범주 내에 세부 정보를 포함할 수 있습니다. 다음 코드 예에는 단일 수신자에 대한 이 구조의 예가 나옵니다.

```
{
  "meta":{
    "userId":"51806220607"
  },
  "contact":{
    "firstName":"Anaya",
    "lastName":"Iyengar",
    "city":"Bengaluru",
    "country":"India",
    "postalCode":"560052"
  },
  "subscription":[
    {
      "interest":"Sports"
    },
    {
      "interest":"Travel"
    },
    {
      "interest":"Cooking"
    }
  ]
}
```

이메일 템플릿에서 상위 속성의 이름 뒤에 마침표(.)와 값을 포함할 속성의 이름을 제공하여 중첩 속성을 참조할 수 있습니다. 예를 들어 앞의 예에 표시된 데이터 구조를 사용하고 이메일 템플릿에 각 수신자의 이름을 포함하려는 경우 이메일 템플릿에 `Hello {{contact.firstName}}!` 텍스트를 포함합니다.

Handlebars는 여러 수준 깊이로 중첩된 경로를 구문 분석할 수 있기 때문에 유연하게 템플릿 데이터를 구성할 수 있습니다.

## 목록 살펴보기
<a name="send-personalized-email-advanced-iterating"></a>

`each` 보조 도구 함수는 어레이로 항목을 살펴봅니다. 다음 코드는 `each` 헬퍼 함수를 사용하여 항목화된 각 수신자의 관심사 목록을 생성하는 이메일 템플릿의 예입니다.

```
{
  "Template": {
    "TemplateName": "Preferences",
    "SubjectPart": "Subscription Preferences for {{contact.firstName}} {{contact.lastName}}",
    "HtmlPart": "<h1>Your Preferences</h1>
                 <p>You have indicated that you are interested in receiving 
                   information about the following subjects:</p>
                 <ul>
                   {{#each subscription}}
                     <li>{{interest}}</li>
                   {{/each}}
                 </ul>
                 <p>You can change these settings at any time by visiting 
                    the <a href=https://www.example.com/prefererences/i.aspx?id={{meta.userId}}>
                    Preference Center</a>.</p>",
    "TextPart": "Your Preferences\n\nYou have indicated that you are interested in 
                 receiving information about the following subjects:\n
                 {{#each subscription}}
                   - {{interest}}\n
                 {{/each}}
                 \nYou can change these settings at any time by 
                 visiting the Preference Center at 
                 https://www.example.com/prefererences/i.aspx?id={{meta.userId}}"
  }
}
```

**중요**  
앞의 코드 예에는 예를 이해하기 쉽도록 `HtmlPart` 및 `TextPart` 속성의 값에 줄 바꿈이 포함되어 있습니다. 템플릿의 JSON 파일에는 이러한 값 내에 줄바꿈이 포함될 수 없습니다. 이 예를 복사하여 자체 JSON 파일에 붙여 넣으면 진행하기 전에 `HtmlPart` 및 `TextPart` 섹션에서 줄 바꿈 및 추가 공백을 제거합니다.

템플릿을 생성한 후 `SendEmail` 또는 `SendBulkEmail` 작업을 사용하여 수신자에게 이 템플릿으로 이메일을 보낼 수 있습니다. 각 수신자가 `Interests` 객체에 최소 하나의 값이 있는 한 항목화된 관심사 목록이 포함되는 이메일을 수신합니다. 다음 예는 앞의 템플릿을 사용하여 여러 수신자에게 이메일을 보내는 데 사용할 수 있는 JSON 템플릿을 보여 줍니다.

```
{
  "Source":"Sender Name <sender@example.com>",
  "Template":"Preferences",
  "Destinations":[
    {
      "Destination":{
        "ToAddresses":[
          "anaya.iyengar@example.com"
        ]
      },
      "ReplacementTemplateData":"{\"meta\":{\"userId\":\"51806220607\"},\"contact\":{\"firstName\":\"Anaya\",\"lastName\":\"Iyengar\"},\"subscription\":[{\"interest\":\"Sports\"},{\"interest\":\"Travel\"},{\"interest\":\"Cooking\"}]}"
      },
    {
      "Destination":{ 
        "ToAddresses":[
          "shirley.rodriguez@example.com"
        ]
      },
      "ReplacementTemplateData":"{\"meta\":{\"userId\":\"1981624758263\"},\"contact\":{\"firstName\":\"Shirley\",\"lastName\":\"Rodriguez\"},\"subscription\":[{\"interest\":\"Technology\"},{\"interest\":\"Politics\"}]}"
    }
  ],
  "DefaultTemplateData":"{\"meta\":{\"userId\":\"\"},\"contact\":{\"firstName\":\"Friend\",\"lastName\":\"\"},\"subscription\":[]}"
}
```

`SendBulkEmail` 작업을 사용하여 앞의 예에 나열된 수신자에게 이메일을 보내면 다음 이미지에 표시된 예와 같은 메시지를 수신합니다.

![\[Preferences notification listing Sports, Travel, and Cooking as selected interests.\]](http://docs.aws.amazon.com/ko_kr/ses/latest/dg/images/send-personalized-email-advanced-condition-interest.png)


## 기본 조건문 사용
<a name="send-personalized-email-advanced-conditionals"></a>

이 섹션은 이전 섹션에서 설명한 예를 기반으로 합니다. 이전 섹션의 예는 `each` 보조 도구를 사용하여 관심사 목록을 살펴봅니다. 하지만 관심사가 지정되지 않은 수신자는 빈 목록이 포함된 이메일을 수신합니다. `{{if}}` 보조 도구를 사용하면 특정 속성이 템플릿 데이터에 있는 경우 이메일의 형식을 다르게 할 수 있습니다. 다음 코드는 `Subscription` 어레이에 값이 포함되는 경우 `{{if}}` 보조 도구를 사용하여 앞 섹션의 글머리표 목록을 표시합니다. 어레이가 비어 있으면 다른 텍스트 블록이 표시됩니다.

```
{
  "Template": {
    "TemplateName": "Preferences2",
    "SubjectPart": "Subscription Preferences for {{contact.firstName}} {{contact.lastName}}",
    "HtmlPart": "<h1>Your Preferences</h1>
                 <p>Dear {{contact.firstName}},</p>
                 {{#if subscription}}
                   <p>You have indicated that you are interested in receiving 
                     information about the following subjects:</p>
                     <ul>
                     {{#each subscription}}
                       <li>{{interest}}</li>
                     {{/each}}
                     </ul>
                     <p>You can change these settings at any time by visiting 
                       the <a href=https://www.example.com/prefererences/i.aspx?id={{meta.userId}}>
                       Preference Center</a>.</p>
                 {{else}}
                   <p>Please update your subscription preferences by visiting 
                     the <a href=https://www.example.com/prefererences/i.aspx?id={{meta.userId}}>
                     Preference Center</a>.
                 {{/if}}",
    "TextPart": "Your Preferences\n\nDear {{contact.firstName}},\n\n
                 {{#if subscription}}
                   You have indicated that you are interested in receiving 
                   information about the following subjects:\n
                   {{#each subscription}}
                     - {{interest}}\n
                   {{/each}}
                   \nYou can change these settings at any time by visiting the 
                   Preference Center at https://www.example.com/prefererences/i.aspx?id={{meta.userId}}.
                 {{else}}
                   Please update your subscription preferences by visiting the 
                   Preference Center at https://www.example.com/prefererences/i.aspx?id={{meta.userId}}.
                 {{/if}}"
  }
}
```

**중요**  
앞의 코드 예에는 예를 이해하기 쉽도록 `HtmlPart` 및 `TextPart` 속성의 값에 줄 바꿈이 포함되어 있습니다. 템플릿의 JSON 파일에는 이러한 값 내에 줄바꿈이 포함될 수 없습니다. 이 예를 복사하여 자체 JSON 파일에 붙여 넣으면 진행하기 전에 `HtmlPart` 및 `TextPart` 섹션에서 줄 바꿈 및 추가 공백을 제거합니다.

다음 예는 앞의 템플릿을 사용하여 여러 수신자에게 이메일을 보내는 데 사용할 수 있는 JSON 템플릿을 보여 줍니다.

```
{
  "Source":"Sender Name <sender@example.com>",
  "Template":"Preferences2",
  "Destinations":[
    {
      "Destination":{
        "ToAddresses":[
          "anaya.iyengar@example.com"
        ]
      },
      "ReplacementTemplateData":"{\"meta\":{\"userId\":\"51806220607\"},\"contact\":{\"firstName\":\"Anaya\",\"lastName\":\"Iyengar\"},\"subscription\":[{\"interest\":\"Sports\"},{\"interest\":\"Cooking\"}]}"
      },
    {
      "Destination":{ 
        "ToAddresses":[
          "shirley.rodriguez@example.com"
        ]
      },
      "ReplacementTemplateData":"{\"meta\":{\"userId\":\"1981624758263\"},\"contact\":{\"firstName\":\"Shirley\",\"lastName\":\"Rodriguez\"}}"
    }
  ],
  "DefaultTemplateData":"{\"meta\":{\"userId\":\"\"},\"contact\":{\"firstName\":\"Friend\",\"lastName\":\"\"},\"subscription\":[]}"
}
```

이 예에서는 템플릿 데이터에 관심사 목록이 포함된 수신자가 이전 섹션에 표시된 예와 같은 이메일을 수신합니다. 하지만 템플릿 데이터에 관심사가 포함되지 않은 수신자는 다음 이미지에 표시된 예와 같은 이메일을 수신합니다.

![\[Email message with header "Your Preferences" and text about updating subscription preferences.\]](http://docs.aws.amazon.com/ko_kr/ses/latest/dg/images/send-personalized-email-advanced-condition-nointerest.png)


## 인라인 부분 생성
<a name="send-personalized-email-advanced-inline-partials"></a>

인라인 부분을 사용하여 반복된 문자열이 포함된 템플릿을 간소화할 수 있습니다. 예를 들어 사용 가능한 경우 템플릿의 첫 부분에 다음 코드를 추가하여 수신자의 이름 및 사용 가능한 경우 성이 포함된 인라인 부분을 만들 수 있습니다.

```
{{#* inline \"fullName\"}}{{firstName}}{{#if lastName}} {{lastName}}{{/if}}{{/inline}}\n
```

**참고**  
줄바꿈 문서(`\n`)는 템플릿의 콘텐츠에서 `{{inline}}` 블록을 분리하는 데 필요합니다. 줄바꿈은 최종 출력에 렌더링되지 않습니다.

`fullName` 부분을 생성한 후 `{{> fullName}}`의 예와 같이 부분의 이름 앞에 이상(>) 기호를 표시하고 공백을 표시하여 템플릿의 어느 부분에든 포함할 수 있습니다. 인라인 부분은 이메일 부분 사이에 전송되지 않습니다. 예를 들어 이메일의 HTML과 텍스트 버전 모두에 동일한 인라인 부분을 사용하려는 경우 `HtmlPart` 및 `TextPart` 섹션 모두에서 정의해야 합니다.

어레이를 통해 살펴보는 경우 인라인 부분을 사용할 수도 있습니다. 다음 코드를 사용하여 `fullName` 인라인 부분을 사용한 템플릿을 생성할 수 있습니다. 이 예에서는 인라인 부분이 수신자의 이름과 다른 이름의 어레이 모두에 적용됩니다.

```
{
  "Template": {
    "TemplateName": "Preferences3",
    "SubjectPart": "{{firstName}}'s Subscription Preferences",
    "HtmlPart": "{{#* inline \"fullName\"}}
                   {{firstName}}{{#if lastName}} {{lastName}}{{/if}}
                 {{/inline~}}\n
                 <h1>Hello {{> fullName}}!</h1>
                 <p>You have listed the following people as your friends:</p>
                 <ul>
                 {{#each friends}}
                   <li>{{> fullName}}</li>
                 {{/each}}</ul>",
    "TextPart": "{{#* inline \"fullName\"}}
                   {{firstName}}{{#if lastName}} {{lastName}}{{/if}}
                 {{/inline~}}\n
                 Hello {{> fullName}}! You have listed the following people 
                 as your friends:\n
                 {{#each friends}}
                   - {{> fullName}}\n
                 {{/each}}"
  }
}
```

**중요**  
앞의 코드 예에는 예를 이해하기 쉽도록 `HtmlPart` 및 `TextPart` 속성의 값에 줄 바꿈이 포함되어 있습니다. 템플릿의 JSON 파일에는 이러한 값 내에 줄바꿈이 포함될 수 없습니다. 이 예를 복사하여 자체 JSON 파일에 붙여 넣으면 진행하기 전에 이 섹션들에서 줄 바꿈 및 추가 공백을 제거합니다.

# 이메일 템플릿 관리
<a name="send-personalized-email-manage-templates"></a>

[이메일 템플릿 만들기](send-personalized-email-api.md) 외에도 Amazon SES v2 API를 사용하여 기존 템플릿을 업데이트 또는 삭제하거나, 기존 템플릿을 모두 나열하거나, 템플릿의 내용을 볼 수도 있습니다.

이 단원에는 AWS CLI 를 사용하여 SES 템플릿과 관련된 작업을 수행하는 절차가 포함되어 있습니다.

**참고**  
이 섹션의 절차는 또한 AWS CLI을(를) 이미 설치하여 구성한 상태를 전제로 설명합니다. 설치 및 구성에 대한 자세한 내용은 [AWS Command Line Interface 사용 설명서를](https://docs.aws.amazon.com/cli/latest/userguide/) AWS CLI참조하세요.

## 이메일 템플릿 목록 보기
<a name="send-personalized-email-manage-templates-list"></a>

[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_ListEmailTemplate.html](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>

[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailTemplate.html](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>

[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_DeleteEmailTemplate.html](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>

[https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_UpdateEmailTemplate.html](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
   ```

   위의 명령에서 *path/to/update\$1template.json*을 이전 단계에서 생성한 `update_template.json` 파일의 경로로 바꿉니다.

   템플릿이 성공적으로 업데이트되면 이 명령은 출력을 제공하지 않습니다. [https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailTemplate.html](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailTemplate.html) 작업을 사용하여 템플릿이 업데이트되었는지 확인할 수 있습니다.

   지정한 템플릿이 존재하지 않는 경우 이 명령은 `TemplateDoesNotExist` 오류를 반환합니다. 템플릿이 `TextPart` 또는 `HtmlPart` 속성(또는 둘 다)를 포함하지 않는 경우 이 명령은 `InvalidParameterValue` 오류를 반환합니다.