

 [AWS SDK for JavaScript V3 API 참조 안내서](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/)는 AWS SDK for JavaScript 버전 3(V3)의 모든 API 작업을 자세히 설명합니다.

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

# Amazon Simple Email Service 예
<a name="ses-examples"></a>

Amazon Simple Email Service(Amazon SES)는 디지털 마케팅 담당자 및 애플리케이션 개발자가 마케팅, 알림 및 거래 이메일을 전송하는 데 도움이 되도록 설계된 클라우드 기반 이메일 전송 서비스입니다. 이 서비스는 이메일을 사용하여 고객과 연락하는 모든 규모의 기업을 위한 안정적이고 비용 효과적인 서비스입니다.

![\[JavaScript 환경, SDK, Amazon SES 간의 관계\]](http://docs.aws.amazon.com/ko_kr/sdk-for-javascript/v3/developer-guide/images/code-samples-ses.png)


Amazon SES용 JavaScript API는 `SES` 클라이언트 클래스를 통해 노출됩니다. Amazon SES 클라이언트 클래스 사용에 관한 자세한 내용은 API 참조의 [Class: SES](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SES/)를 참조하세요.

**Topics**
+ [Amazon SES 자격 증명 관리](ses-examples-managing-identities.md)
+ [Amazon SES에서 이메일 템플릿 작업](ses-examples-creating-template.md)
+ [Amazon SES를 사용하여 이메일 전송](ses-examples-sending-email.md)

# Amazon SES 자격 증명 관리
<a name="ses-examples-managing-identities"></a>

![\[JavaScript code example that applies to Node.js execution\]](http://docs.aws.amazon.com/ko_kr/sdk-for-javascript/v3/developer-guide/images/nodeicon.png)

**이 Node.js 코드 예제는 다음을 보여 줍니다.**
+ Amazon SES에 사용되는 이메일 주소 및 도메인을 확인하는 방법
+ Amazon SES 자격 증명에 AWS Identity and Access Management (IAM) 정책을 할당하는 방법.
+  AWS 계정의 모든 Amazon SES 자격 증명을 나열하는 방법.
+ Amazon SES에 사용되는 자격 증명을 삭제하는 방법

Amazon SES *자격 증명*은 Amazon SES에서 이메일을 보내는 데 사용하는 이메일 주소 또는 도메인입니다. Amazon SES에서는 이메일 자격 증명을 확인해야 합니다. 이렇게 해당 자격 증명을 소유하고 있음을 확인하고 다른 사람이 이를 사용하지 못하게 방지합니다.

Amazon SES에서 이메일 주소 및 도메인을 확인하는 방법에 대한 자세한 내용은 Amazon Simple Email Service 개발자 안내서의 [Amazon SES에서 확인된 자격 증명](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-addresses-and-domains.html) 단원을 참조하세요. Amazon SES의 전송 권한 부여에 관한 자세한 내용은 [Overview of Amazon SES sending authorization](Amazon Simple Email Service Developer Guidesending-authorization-overview.html) 단원을 참조하세요.

## 시나리오
<a name="ses-examples-verifying-identities-scenario"></a>

이 예에서는 일련의 Node.js 모듈을 사용하여 Amazon SES 자격 증명을 확인하고 관리합니다. 이 Node.js 모듈은 SDK for JavaScript에서 `SES` 클라이언트 클래스의 다음 메서드를 사용하여 이메일 주소와 도메인을 확인합니다.
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/ListIdentitiesCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/ListIdentitiesCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/DeleteIdentityCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/DeleteIdentityCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/VerifyEmailIdentityCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/VerifyEmailIdentityCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/VerifyDomainIdentityCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/VerifyDomainIdentityCommand/)

## 사전 필수 작업
<a name="ses-examples-verifying-identities-prerequisites"></a>

이 예제를 설정하고 실행하려면 먼저 이러한 작업들을 완료해야 합니다.
+ 이러한 노드 TypeScript 예제를 실행하도록 프로젝트 환경을 설정하고 필요한 AWS SDK for JavaScript 모듈과 타사 모듈을 설치합니다. [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/ses/README.md)의 지침을 따릅니다.
+ 사용자 자격 증명을 사용하여 공유 구성 파일을 생성합니다. 공유 보안 인증 파일 제공에 관한 자세한 내용은 *AWS SDK 및 도구 참조 가이드*의 [Shared config and credentials files](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) 단원을 참조하세요.

**중요**  
이 예는 ECMAScript6(ES6)를 사용하여 클라이언트 서비스 객체 및 명령을 가져오거나 내보내는 방법을 보여줍니다.  
따라서 Node.js 버전 13.x 이상이 필요합니다. 최신 버전의 Node.js를 다운로드하여 설치하려면 [Node.js downloads](https://nodejs.org/en/download)를 참조하세요.
CommonJS 구문을 사용하려는 경우 [JavaScript ES6/CommonJS 구문](sdk-example-javascript-syntax.md) 단원을 참조하세요.

## 자격 증명 나열
<a name="ses-examples-listing-identities"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 주소와 도메인을 나열합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_listidentities.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `ListIdentitiesCommand` 메서드에 대한 `IdentityType` 및 기타 파라미터를 전달할 객체를 생성합니다. `ListIdentitiesCommand` 메서드를 직접적으로 호출하려면 Amazon SES 서비스 객체를 간접적으로 호출하여 파라미터 객체를 전달합니다.

 반환된 `data`에는 `IdentityType` 파라미터로 지정된 도메인 자격 증명 배열이 포함되어 있습니다.

**참고**  
*IdentityType*을 자격 증명 유형("EmailAddress" 또는 "Domain"일 수 있음)으로 바꿉니다.

```
import { ListIdentitiesCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";

const createListIdentitiesCommand = () =>
  new ListIdentitiesCommand({ IdentityType: "EmailAddress", MaxItems: 10 });

const run = async () => {
  const listIdentitiesCommand = createListIdentitiesCommand();

  try {
    return await sesClient.send(listIdentitiesCommand);
  } catch (err) {
    console.log("Failed to list identities.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다.

```
node ses_listidentities.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_listidentities.js) 찾을 수 있습니다.

## 이메일 주소 자격 증명 확인
<a name="ses-examples-verifying-email"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 발신자를 확인합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_verifyemailidentity.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 다운로드를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `VerifyEmailIdentityCommand` 메서드에 대한 `EmailAddress` 파라미터를 전달할 객체를 생성합니다. `VerifyEmailIdentityCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
*EMAIL\$1ADDRESS*를 name@example.com과 같은 이메일 주소로 바꿉니다.

```
// Import required AWS SDK clients and commands for Node.js
import { VerifyEmailIdentityCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";

const EMAIL_ADDRESS = "name@example.com";

const createVerifyEmailIdentityCommand = (emailAddress) => {
  return new VerifyEmailIdentityCommand({ EmailAddress: emailAddress });
};

const run = async () => {
  const verifyEmailIdentityCommand =
    createVerifyEmailIdentityCommand(EMAIL_ADDRESS);
  try {
    return await sesClient.send(verifyEmailIdentityCommand);
  } catch (err) {
    console.log("Failed to verify email identity.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. 도메인이 확인을 위해 Amazon SES에 추가됩니다.

```
node ses_verifyemailidentity.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_verifyemailidentity.js) 찾을 수 있습니다.

## 도메인 자격 증명 확인
<a name="ses-examples-verifying-domains"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 도메인을 확인합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_verifydomainidentity.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `VerifyDomainIdentityCommand` 메서드에 대한 `Domain` 파라미터를 전달할 객체를 생성합니다. `VerifyDomainIdentityCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하여 파라미터 객체를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*DOMAIN\$1NAME*을 도메인 이름으로 바꿉니다.

```
import { VerifyDomainIdentityCommand } from "@aws-sdk/client-ses";
import {
  getUniqueName,
  postfix,
} from "@aws-doc-sdk-examples/lib/utils/util-string.js";
import { sesClient } from "./libs/sesClient.js";

/**
 * You must have access to the domain's DNS settings to complete the
 * domain verification process.
 */
const DOMAIN_NAME = postfix(getUniqueName("Domain"), ".example.com");

const createVerifyDomainIdentityCommand = () => {
  return new VerifyDomainIdentityCommand({ Domain: DOMAIN_NAME });
};

const run = async () => {
  const VerifyDomainIdentityCommand = createVerifyDomainIdentityCommand();

  try {
    return await sesClient.send(VerifyDomainIdentityCommand);
  } catch (err) {
    console.log("Failed to verify domain.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. 도메인이 확인을 위해 Amazon SES에 추가됩니다.

```
node ses_verifydomainidentity.js  
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_verifydomainidentity.js) 찾을 수 있습니다.

## 자격 증명 삭제
<a name="ses-examples-deleting-identities"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용되는 이메일 주소 또는 도메인을 삭제합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_deleteidentity.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `DeleteIdentityCommand` 메서드에 대한 `Identity` 파라미터를 전달할 객체를 생성합니다. `DeleteIdentityCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하기 위한 `request`를 생성하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*IDENTITY\$1EMAIL*을 삭제할 자격 증명의 이메일로 바꿉니다.

```
import { DeleteIdentityCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";

const IDENTITY_EMAIL = "fake@example.com";

const createDeleteIdentityCommand = (identityName) => {
  return new DeleteIdentityCommand({
    Identity: identityName,
  });
};

const run = async () => {
  const deleteIdentityCommand = createDeleteIdentityCommand(IDENTITY_EMAIL);

  try {
    return await sesClient.send(deleteIdentityCommand);
  } catch (err) {
    console.log("Failed to delete identity.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다.

```
node ses_deleteidentity.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_deleteidentity.js) 찾을 수 있습니다.

# Amazon SES에서 이메일 템플릿 작업
<a name="ses-examples-creating-template"></a>

![\[JavaScript code example that applies to Node.js execution\]](http://docs.aws.amazon.com/ko_kr/sdk-for-javascript/v3/developer-guide/images/nodeicon.png)

**이 Node.js 코드 예제는 다음을 보여 줍니다.**
+ 모든 이메일 템플릿 목록을 가져오는 방법
+ 이메일 템플릿을 검색하고 업데이트하는 방법
+ 이메일 템플릿을 생성하고 삭제하는 방법

Amazon SES에서 이메일 템플릿을 사용하여 맞춤형 이메일 메시지를 전송할 수 있습니다. Amazon SES에서 이메일 템플릿을 생성하고 사용하는 방법에 대한 자세한 내용은 Amazon Simple Email Service 개발자 안내서의 [템플릿을 사용하여 Amazon SES API를 통해 맞춤형 이메일 전송](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html) 단원을 참조하세요.

## 시나리오
<a name="ses-examples-creating-template-scenario"></a>

이 예제에서는 일련의 Node.js 모듈을 사용하여 이메일 템플릿을 작업합니다. 이 Node.js 모듈은 SDK for JavaScript에서 `SES` 클라이언트 클래스의 다음 메서드를 사용하여 이메일 템플릿을 생성하고 사용합니다.
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/ListTemplatesCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/ListTemplatesCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/CreateTemplateCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/CreateTemplateCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/GetTemplateCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/GetTemplateCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/DeleteTemplateCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/DeleteTemplateCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/UpdateTemplateCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/UpdateTemplateCommand/)

## 사전 필수 작업
<a name="ses-examples-creating-template-prerequisites"></a>

이 예제를 설정하고 실행하려면 먼저 이러한 작업들을 완료해야 합니다.
+ 이러한 노드 TypeScript 예제를 실행하도록 프로젝트 환경을 설정하고 필요한 AWS SDK for JavaScript 모듈과 타사 모듈을 설치합니다. [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/ses/README.md)의 지침을 따릅니다.
+ 사용자 자격 증명을 사용하여 공유 구성 파일을 생성합니다. 공유 보안 인증 파일 제공에 관한 자세한 내용은 *AWS SDK 및 도구 참조 가이드*의 [Shared config and credentials files](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) 단원을 참조하세요.

**중요**  
이 예는 ECMAScript6(ES6)를 사용하여 클라이언트 서비스 객체 및 명령을 가져오거나 내보내는 방법을 보여줍니다.  
따라서 Node.js 버전 13.x 이상이 필요합니다. 최신 버전의 Node.js를 다운로드하여 설치하려면 [Node.js downloads](https://nodejs.org/en/download)를 참조하세요.
CommonJS 구문을 사용하려는 경우 [JavaScript ES6/CommonJS 구문](sdk-example-javascript-syntax.md) 단원을 참조하세요.

## 이메일 템플릿 나열
<a name="ses-examples-listing-templates"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 템플릿을 생성합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_listtemplates.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `ListTemplatesCommand` 메서드에 대한 파라미터를 전달할 객체를 생성합니다. `ListTemplatesCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

```
import { ListTemplatesCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";

const createListTemplatesCommand = (maxItems) =>
  new ListTemplatesCommand({ MaxItems: maxItems });

const run = async () => {
  const listTemplatesCommand = createListTemplatesCommand(10);

  try {
    return await sesClient.send(listTemplatesCommand);
  } catch (err) {
    console.log("Failed to list templates.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. Amazon SES가 템플릿 목록을 반환합니다.

```
node ses_listtemplates.js  
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_listtemplates.js) 찾을 수 있습니다.

## 이메일 템플릿 가져오기
<a name="ses-examples-get-template"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 템플릿을 가져옵니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_gettemplate.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `GetTemplateCommand` 메서드에 대한 `TemplateName` 파라미터를 전달할 객체를 생성합니다. `GetTemplateCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*TEMPLATE\$1NAME*을 반환할 템플릿의 이름으로 바꿉니다.

```
import { GetTemplateCommand } from "@aws-sdk/client-ses";
import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js";
import { sesClient } from "./libs/sesClient.js";

const TEMPLATE_NAME = getUniqueName("TemplateName");

const createGetTemplateCommand = (templateName) =>
  new GetTemplateCommand({ TemplateName: templateName });

const run = async () => {
  const getTemplateCommand = createGetTemplateCommand(TEMPLATE_NAME);

  try {
    return await sesClient.send(getTemplateCommand);
  } catch (caught) {
    if (caught instanceof Error && caught.name === "MessageRejected") {
      /** @type { import('@aws-sdk/client-ses').MessageRejected} */
      const messageRejectedError = caught;
      return messageRejectedError;
    }
    throw caught;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. Amazon SES가 템플릿 세부 정보를 반환합니다.

```
node ses_gettemplate.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_gettemplate.js) 찾을 수 있습니다.

## 이메일 템플릿 생성
<a name="ses-examples-create-template"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 템플릿을 생성합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_createtemplate.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`TemplateName`, `HtmlPart`, `SubjectPart` 및 `TextPart`를 포함하여 `SES` 클라이언트 클래스의 `CreateTemplateCommand` 메서드에 대한 파라미터를 전달할 객체를 생성합니다. `CreateTemplateCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*TEMPLATE\$1NAME*을 새 템플릿의 이름으로 바꾸고, *HtmlPart*를 이메일의 HTML 태그 지정 콘텐츠로 바꾸고, *SubjectPart*를 이메일 제목으로 바꿉니다.

```
import { CreateTemplateCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";
import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js";

const TEMPLATE_NAME = getUniqueName("TestTemplateName");

const createCreateTemplateCommand = () => {
  return new CreateTemplateCommand({
    /**
     * The template feature in Amazon SES is based on the Handlebars template system.
     */
    Template: {
      /**
       * The name of an existing template in Amazon SES.
       */
      TemplateName: TEMPLATE_NAME,
      HtmlPart: `
        <h1>Hello, {{contact.firstName}}!</h1>
        <p>
        Did you know Amazon has a mascot named Peccy?
        </p>
      `,
      SubjectPart: "Amazon Tip",
    },
  });
};

const run = async () => {
  const createTemplateCommand = createCreateTemplateCommand();

  try {
    return await sesClient.send(createTemplateCommand);
  } catch (err) {
    console.log("Failed to create template.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. 템플릿이 Amazon SES에 추가됩니다.

```
node ses_createtemplate.js  
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_createtemplate.js) 찾을 수 있습니다.

## 이메일 템플릿 업데이트
<a name="ses-examples-update-template"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 템플릿을 생성합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_updatetemplate.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `UpdateTemplateCommand` 메서드에 전달된 필수 `TemplateName` 파라미터와 함께 템플릿에서 업데이트하려는 `Template` 파라미터 값을 전달할 객체를 생성합니다. `UpdateTemplateCommand` 메서드를 직접적으로 호출하려면 Amazon SES 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*TEMPLATE\$1NAME*을 템플릿 이름으로 바꾸고 *HTML\$1PART*를 HTML 태그가 지정된 이메일 콘텐츠로 바꿉니다.

```
import { UpdateTemplateCommand } from "@aws-sdk/client-ses";
import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js";
import { sesClient } from "./libs/sesClient.js";

const TEMPLATE_NAME = getUniqueName("TemplateName");
const HTML_PART = "<h1>Hello, World!</h1>";

const createUpdateTemplateCommand = () => {
  return new UpdateTemplateCommand({
    Template: {
      TemplateName: TEMPLATE_NAME,
      HtmlPart: HTML_PART,
      SubjectPart: "Example",
      TextPart: "Updated template text.",
    },
  });
};

const run = async () => {
  const updateTemplateCommand = createUpdateTemplateCommand();

  try {
    return await sesClient.send(updateTemplateCommand);
  } catch (err) {
    console.log("Failed to update template.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. Amazon SES가 템플릿 세부 정보를 반환합니다.

```
node ses_updatetemplate.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_updatetemplate.js) 찾을 수 있습니다.

## 이메일 템플릿 삭제
<a name="ses-examples-delete-template"></a>

이 예에서는 Node.js 모듈을 사용하여 Amazon SES에 사용할 이메일 템플릿을 생성합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_deletetemplate.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

`SES` 클라이언트 클래스의 `DeleteTemplateCommand` 메서드에 필수 `TemplateName` 파라미터를 전달할 객체를 생성합니다. `DeleteTemplateCommand` 메서드를 직접적으로 호출하려면 Amazon SES 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*TEMPLATE\$1NAME*을 삭제할 템플릿의 이름으로 바꿉니다.

```
import { DeleteTemplateCommand } from "@aws-sdk/client-ses";
import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js";
import { sesClient } from "./libs/sesClient.js";

const TEMPLATE_NAME = getUniqueName("TemplateName");

const createDeleteTemplateCommand = (templateName) =>
  new DeleteTemplateCommand({ TemplateName: templateName });

const run = async () => {
  const deleteTemplateCommand = createDeleteTemplateCommand(TEMPLATE_NAME);

  try {
    return await sesClient.send(deleteTemplateCommand);
  } catch (err) {
    console.log("Failed to delete template.", err);
    return err;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. Amazon SES가 템플릿 세부 정보를 반환합니다.

```
node ses_deletetemplate.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_deletetemplate.js) 찾을 수 있습니다.

# Amazon SES를 사용하여 이메일 전송
<a name="ses-examples-sending-email"></a>

![\[JavaScript code example that applies to Node.js execution\]](http://docs.aws.amazon.com/ko_kr/sdk-for-javascript/v3/developer-guide/images/nodeicon.png)

**이 Node.js 코드 예제는 다음을 보여 줍니다.**
+ 테스트 또는 HTML 이메일을 전송합니다.
+ 이메일 템플릿을 기반으로 이메일을 전송합니다.
+ 이메일 템플릿을 기반으로 대량 이메일을 전송합니다.

Amazon SES API에서는 이메일 메시지 작성에 대해 원하는 제어 정도에 따라 서식 지정 및 원시라는 두 가지 이메일 전송 방법을 선택할 수 있습니다. 자세한 내용은 [Amazon SES API를 사용하여 서식이 지정된 이메일 보내기](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-formatted.html) 및 [Amazon SES API를 사용하여 원시 이메일 보내기](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-raw.html) 단원을 참조하세요.

## 시나리오
<a name="ses-examples-sending-email-scenario"></a>

이 예제에서는 일련의 Node.js 모듈을 사용하여 다양한 방법으로 이메일을 전송합니다. 이 Node.js 모듈은 SDK for JavaScript에서 `SES` 클라이언트 클래스의 다음 메서드를 사용하여 이메일 템플릿을 생성하고 사용합니다.
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SendEmailCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SendEmailCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SendTemplatedEmailCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SendTemplatedEmailCommand/)
+ [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SendBulkTemplatedEmailCommand/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Class/SendBulkTemplatedEmailCommand/)

## 사전 필수 작업
<a name="ses-examples-sending-emails-prerequisites"></a>

이 예제를 설정하고 실행하려면 먼저 이러한 작업들을 완료해야 합니다.
+ 이러한 노드 TypeScript 예제를 실행하도록 프로젝트 환경을 설정하고 필요한 AWS SDK for JavaScript 모듈과 타사 모듈을 설치합니다. [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/ses/README.md)의 지침을 따릅니다.
+ 사용자 자격 증명을 사용하여 공유 구성 파일을 생성합니다. 공유 보안 인증 파일 제공에 관한 자세한 내용은 *AWS SDK 및 도구 참조 가이드*의 [Shared config and credentials files](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) 단원을 참조하세요.

**중요**  
이 예는 ECMAScript6(ES6)를 사용하여 클라이언트 서비스 객체 및 명령을 가져오거나 내보내는 방법을 보여줍니다.  
따라서 Node.js 버전 13.x 이상이 필요합니다. 최신 버전의 Node.js를 다운로드하여 설치하려면 [Node.js downloads](https://nodejs.org/en/download)를 참조하세요.
CommonJS 구문을 사용하려는 경우 [JavaScript ES6/CommonJS 구문](sdk-example-javascript-syntax.md) 단원을 참조하세요.

## 이메일 메시지 전송 요구 사항
<a name="ses-examples-sending-msail-reqs"></a>

Amazon SES에서는 이메일 메시지를 작성하는 즉시 전송 대기열에 넣습니다. `SendEmailCommand` 메서드를 사용하여 이메일을 전송하려면 메시지는 다음 요구 사항을 충족해야 합니다.
+ 확인된 이메일 주소 또는 도메인에서 메시지를 전송해야 합니다. 확인되지 않은 주소 또는 도메인을 사용하여 이메일을 전송하려고 시도하면 작업 결과로 `"Email address not verified"` 오류가 발생합니다.
+ 계정이 여전히 Amazon SES 샌드박스에 있는 경우 확인된 주소 또는 도메인으로만 또는 Amazon SES 메일박스 시뮬레이터와 연결된 이메일 주소로만 전송할 수 있습니다. 자세한 내용은 Amazon Simple Email Service 개발자 안내서의 [Amazon SES에서 확인된 자격 증명](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-addresses-and-domains.html) 단원을 참조하세요.
+ 첨부 파일을 포함한 메시지의 총 크기는 10MB 미만이어야 합니다.
+ 메시지에 최소 하나 이상의 수신자 이메일 주소가 포함되어야 합니다. 수신자 주소는 받는 사람: 주소, 참조: 주소 또는 숨은 참조: 주소일 수 있습니다. 수신자 이메일 주소가 유효하지 않은 경우(즉, `UserName@[SubDomain.]Domain.TopLevelDomain` 형식이 아닌 경우) 메시지에 유효한 다른 수신자가 포함되어 있더라도 전체 메시지가 거부됩니다.
+ 메시지에는 받는 사람:, 참조: 및 숨은 참조: 필드 전체에서 50명을 초과하는 수신자가 포함될 수 없습니다. 더 많은 대상에게 이메일 메시지를 전송해야 하는 경우 수신자 목록을 50명 이하의 여러 그룹으로 나눈 다음 `sendEmail` 메서드를 여러 번 호출하여 각 그룹에게 메시지를 전송할 수 있습니다.

## 이메일 전송
<a name="ses-examples-sendmail"></a>

이 예제에서는 Node.js 모듈을 사용하여 Amazon SES에서 이메일을 전송합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_sendemail.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

발신자 및 수신자 주소, 제목, 일반 텍스트 및 HTML 형식의 이메일 본문을 포함하여 전송할 이메일을 정의하는 파라미터 값을 `SES` 클라이언트 클래스의 `SendEmailCommand` 메서드에 전달할 객체를 생성합니다. `SendEmailCommand` 메서드를 직접적으로 호출하려면 Amazon SES 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*toAddress*를 이메일 수신자의 주소로 바꾸고, *fromAddress*를 이메일 발신자의 이메일 주소로 바꿉니다.

```
import { SendEmailCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";

const createSendEmailCommand = (toAddress, fromAddress) => {
  return new SendEmailCommand({
    Destination: {
      /* required */
      CcAddresses: [
        /* more items */
      ],
      ToAddresses: [
        toAddress,
        /* more To-email addresses */
      ],
    },
    Message: {
      /* required */
      Body: {
        /* required */
        Html: {
          Charset: "UTF-8",
          Data: "HTML_FORMAT_BODY",
        },
        Text: {
          Charset: "UTF-8",
          Data: "TEXT_FORMAT_BODY",
        },
      },
      Subject: {
        Charset: "UTF-8",
        Data: "EMAIL_SUBJECT",
      },
    },
    Source: fromAddress,
    ReplyToAddresses: [
      /* more items */
    ],
  });
};

const run = async () => {
  const sendEmailCommand = createSendEmailCommand(
    "recipient@example.com",
    "sender@example.com",
  );

  try {
    return await sesClient.send(sendEmailCommand);
  } catch (caught) {
    if (caught instanceof Error && caught.name === "MessageRejected") {
      /** @type { import('@aws-sdk/client-ses').MessageRejected} */
      const messageRejectedError = caught;
      return messageRejectedError;
    }
    throw caught;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. 이메일이 Amazon SES에서 전송하기 위해 대기됩니다.

```
node ses_sendemail.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_sendemail.js) 찾을 수 있습니다.

## 템플릿을 사용한 이메일 전송
<a name="ses-examples-sendtemplatedemail"></a>

이 예제에서는 Node.js 모듈을 사용하여 Amazon SES에서 이메일을 전송합니다. 파일 이름이 `ses_sendtemplatedemail.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

발신자 및 수신자 주소, 제목, 일반 텍스트 및 HTML 형식의 이메일 본문을 포함하여 전송할 이메일을 정의하는 파라미터 값을 `SES` 클라이언트 클래스의 `SendTemplatedEmailCommand` 메서드에 전달할 객체를 생성합니다. `SendTemplatedEmailCommand` 메서드를 직접적으로 호출하려면 Amazon SES 클라이언트 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*REGION*을 AWS 리전으로, *USER*를 이메일을 보낼 이름과 이메일 주소로, *VERIFIED\$1EMAIL*을 이메일을 보낼 이메일 주소로, *TEMPLATE\$1NAME*을 템플릿 이름으로 바꿉니다.

```
import { SendTemplatedEmailCommand } from "@aws-sdk/client-ses";
import {
  getUniqueName,
  postfix,
} from "@aws-doc-sdk-examples/lib/utils/util-string.js";
import { sesClient } from "./libs/sesClient.js";

/**
 * Replace this with the name of an existing template.
 */
const TEMPLATE_NAME = getUniqueName("ReminderTemplate");

/**
 * Replace these with existing verified emails.
 */
const VERIFIED_EMAIL = postfix(getUniqueName("Bilbo"), "@example.com");

const USER = { firstName: "Bilbo", emailAddress: VERIFIED_EMAIL };

/**
 *
 * @param { { emailAddress: string, firstName: string } } user
 * @param { string } templateName - The name of an existing template in Amazon SES.
 * @returns { SendTemplatedEmailCommand }
 */
const createReminderEmailCommand = (user, templateName) => {
  return new SendTemplatedEmailCommand({
    /**
     * Here's an example of how a template would be replaced with user data:
     * Template: <h1>Hello {{contact.firstName}},</h1><p>Don't forget about the party gifts!</p>
     * Destination: <h1>Hello Bilbo,</h1><p>Don't forget about the party gifts!</p>
     */
    Destination: { ToAddresses: [user.emailAddress] },
    TemplateData: JSON.stringify({ contact: { firstName: user.firstName } }),
    Source: VERIFIED_EMAIL,
    Template: templateName,
  });
};

const run = async () => {
  const sendReminderEmailCommand = createReminderEmailCommand(
    USER,
    TEMPLATE_NAME,
  );
  try {
    return await sesClient.send(sendReminderEmailCommand);
  } catch (caught) {
    if (caught instanceof Error && caught.name === "MessageRejected") {
      /** @type { import('@aws-sdk/client-ses').MessageRejected} */
      const messageRejectedError = caught;
      return messageRejectedError;
    }
    throw caught;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. 이메일이 Amazon SES에서 전송하기 위해 대기됩니다.

```
node ses_sendtemplatedemail.js 
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_sendtemplatedemail.js) 찾을 수 있습니다.

## 템플릿을 사용한 대량 이메일 전송
<a name="ses-examples-sendbulktemplatedemail"></a>

이 예제에서는 Node.js 모듈을 사용하여 Amazon SES에서 이메일을 전송합니다.

`libs` 디렉터리를 생성하고 파일 이름이 `sesClient.js`인 Node.js 모듈을 생성합니다. 이 모듈에 아래 코드를 복사하여 붙여 넣으면 Amazon SES 클라이언트 객체가 생성됩니다. *REGION*을 해당 AWS 리전으로 바꿉니다.

```
import { SESClient } from "@aws-sdk/client-ses";
// Set the AWS Region.
const REGION = "us-east-1";
// Credentials are automatically resolved using the AWS SDK credential provider chain.
// For more information, see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
// Create SES service object.
const sesClient = new SESClient({ region: REGION });
export { sesClient };
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/libs/sesClient.js) 찾을 수 있습니다.

파일 이름이 `ses_sendbulktemplatedemail.js`인 Node.js 모듈을 생성합니다. 필수 클라이언트 및 패키지 설치를 포함하여 앞서 나와 있는 것처럼 SDK를 구성합니다.

발신자 및 수신자 주소, 제목, 일반 텍스트 및 HTML 형식의 이메일 본문을 포함하여 전송할 이메일을 정의하는 파라미터 값을 `SES` 클라이언트 클래스의 `SendBulkTemplatedEmailCommand` 메서드에 전달할 객체를 생성합니다. `SendBulkTemplatedEmailCommand` 메서드를 직접적으로 호출하려면 Amazon SES 서비스 객체를 간접적으로 호출하여 파라미터를 전달합니다.

**참고**  
이 예제에서는 필요한 AWS Service V3 패키지 클라이언트, V3 명령을 가져오고 사용하며 비동기/대기 패턴에서 `send` 메서드를 사용합니다. 대신 몇 가지 사소한 변경을 통해 V2 명령을 사용하여 이 예를 생성할 수 있습니다. 자세한 내용은 [v3 명령 사용](migrating.md#using_v3_commands)을 참조하세요.

**참고**  
*USERS*를 이메일 수신자의 이름과 이메일 주소로 바꾸고, *VERIFIED\$1EMAIL\$11*을 이메일 발신자의 이메일 주소로 바꾸고, *TEMPLATE\$1NAME*을 템플릿 이름으로 바꿉니다.

```
import { SendBulkTemplatedEmailCommand } from "@aws-sdk/client-ses";
import {
  getUniqueName,
  postfix,
} from "@aws-doc-sdk-examples/lib/utils/util-string.js";
import { sesClient } from "./libs/sesClient.js";

/**
 * Replace this with the name of an existing template.
 */
const TEMPLATE_NAME = getUniqueName("ReminderTemplate");

/**
 * Replace these with existing verified emails.
 */
const VERIFIED_EMAIL_1 = postfix(getUniqueName("Bilbo"), "@example.com");
const VERIFIED_EMAIL_2 = postfix(getUniqueName("Frodo"), "@example.com");

const USERS = [
  { firstName: "Bilbo", emailAddress: VERIFIED_EMAIL_1 },
  { firstName: "Frodo", emailAddress: VERIFIED_EMAIL_2 },
];

/**
 *
 * @param { { emailAddress: string, firstName: string }[] } users
 * @param { string } templateName the name of an existing template in SES
 * @returns { SendBulkTemplatedEmailCommand }
 */
const createBulkReminderEmailCommand = (users, templateName) => {
  return new SendBulkTemplatedEmailCommand({
    /**
     * Each 'Destination' uses a corresponding set of replacement data. We can map each user
     * to a 'Destination' and provide user specific replacement data to create personalized emails.
     *
     * Here's an example of how a template would be replaced with user data:
     * Template: <h1>Hello {{name}},</h1><p>Don't forget about the party gifts!</p>
     * Destination 1: <h1>Hello Bilbo,</h1><p>Don't forget about the party gifts!</p>
     * Destination 2: <h1>Hello Frodo,</h1><p>Don't forget about the party gifts!</p>
     */
    Destinations: users.map((user) => ({
      Destination: { ToAddresses: [user.emailAddress] },
      ReplacementTemplateData: JSON.stringify({ name: user.firstName }),
    })),
    DefaultTemplateData: JSON.stringify({ name: "Shireling" }),
    Source: VERIFIED_EMAIL_1,
    Template: templateName,
  });
};

const run = async () => {
  const sendBulkTemplateEmailCommand = createBulkReminderEmailCommand(
    USERS,
    TEMPLATE_NAME,
  );
  try {
    return await sesClient.send(sendBulkTemplateEmailCommand);
  } catch (caught) {
    if (caught instanceof Error && caught.name === "MessageRejected") {
      /** @type { import('@aws-sdk/client-ses').MessageRejected} */
      const messageRejectedError = caught;
      return messageRejectedError;
    }
    throw caught;
  }
};
```

예를 실행하려면 명령 프롬프트에서 다음을 입력합니다. 이메일이 Amazon SES에서 전송하기 위해 대기됩니다.

```
node ses_sendbulktemplatedemail.js
```

이 코드 예는 [여기 GitHub에서](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/ses/src/ses_sendbulktemplatedemail.js) 찾을 수 있습니다.