

 [AWS SDK for JavaScript V3 API リファレンスガイド](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/)では、 AWS SDK for JavaScript バージョン3 (V3) のすべての API オペレーションについて詳しく説明します。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon SES アイデンティティの管理
<a name="ses-examples-managing-identities"></a>

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

**この Node.js コード例は以下を示しています。**
+ Amazon SES で使用されている E メールアドレスとドメインを確認する方法。
+  AWS Identity and Access Management (IAM) ポリシーを Amazon SES ID に割り当てる方法。
+  AWS アカウントのすべての Amazon SES ID を一覧表示する方法。
+ Amazon SES で使用されているアイデンティティを削除する方法。

Amazon SES *アイデンティティ*は、Amazon SES が E メールの送信に使用する E メールアドレスまたはドメインです。Amazon SES では、E メールアイデンティティを検証して、それを所有していることを確認し、他のユーザーに使用されないようにする必要があります。

Amazon SES の E メールアドレスとドメインを確認する方法の詳細については、Amazon Simple Email Service デベロッパーガイドの[Amazon SESでのEメールアドレスとドメインの検証](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-addresses-and-domains.html)を参照してください。Amazon SES での送信認可の詳細については、[Amazon SES 送信認可の概要](Amazon Simple Email Service Developer Guidesending-authorization-overview.html)を参照してください。

## シナリオ
<a name="ses-examples-verifying-identities-scenario"></a>

この例では、一連の Node.js モジュールを使用して Amazon SES のアイデンティティを検証および管理します。Node.js モジュールは、`SES` クライアントクラスの次のメソッドを使用し、SDK for JavaScript を使用して E メールアドレスとドメインを検証します。
+ [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>

この例をセットアップして実行するには、まず次のタスクを完了する必要があります。
+ これらの Node TypeScript の例を実行するようにプロジェクト環境を設定し、必要な AWS SDK for JavaScript モジュールとサードパーティーモジュールをインストールします。「[GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/ses/README.md)」の指示に従います。　
+ ユーザーの認証情報を使用して、共有設定ファイルを作成します。共有認証情報ファイルの提供の詳細については、「*AWS SDK とツールのリファレンスガイド*」の「[共有設定ファイルおよび認証情報ファイル](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html)」を参照してください。

**重要**  
これらの例は、ECMAScript6 (ES6) を使用してクライアントサービスオブジェクトとコマンドをimport/export する方法を示します。  
これには Node.js バージョン13.x以降が必要です。Node.js の最新バージョンをダウンロードしてインストールするには、「[Node.js ダウンロード](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 で使用する E メールアドレスとドメインを一覧表示します。

`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`パラメーターで指定されたドメインIDの配列が含まれます。

**注記**  
*IdentityType*を「EmailAddress」または「Domain」のIDタイプに置き換えます。

```
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)で見つけられます。

## E メールアドレスアイデンティの検証
<a name="ses-examples-verifying-email"></a>

この例では、Node.js モジュールを使用して Amazon SES で使用する E メールの送信者を検証します。

`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 などの E メールアドレスに置き換えます。

```
// 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)で見つけられます。

## ドメイン ID の検証
<a name="ses-examples-verifying-domains"></a>

この例では、Node.js モジュールを使用して Amazon SES で使用する E メールのドメインを検証します。

`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 で使用されている E メールアドレスまたはドメインを削除します。

`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* を削除対象の ID の E メールアドレスに置き換えます。

```
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)で見つけられます。