Amazon ID SES の管理 - AWS SDK for JavaScript

AWS SDK for JavaScript V3 APIリファレンスガイドでは、バージョン 3 (V3) のすべてのAPIオペレーションについて詳しく説明しています AWS SDK for JavaScript 。

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

Amazon ID SES の管理

JavaScript code example that applies to Node.js execution

この Node.js コード例は以下を示しています。

  • Amazon で使用される E メールアドレスとドメインを確認する方法SES。

  • Amazon ID に AWS Identity and Access Management (IAM) SES ポリシーを割り当てる方法。

  • AWS アカウントのすべての Amazon ID SES を一覧表示する方法。

  • Amazon で使用される ID を削除する方法SES。

Amazon SES ID は、Amazon が E メールを送信SESするために使用する E メールアドレスまたはドメインです。Amazon SESでは、E メール ID を検証し、自分が所有していることを確認し、他のユーザーによる使用を防止する必要があります。

Amazon で E メールアドレスとドメインを検証する方法の詳細についてはSES、Amazon Simple Email Service デベロッパーガイドの「Amazon での E メールアドレスとドメインSESの検証」を参照してください。Amazon での送信承認の詳細についてはSES、「Amazon SES送信承認の概要」を参照してください。

シナリオ

この例では、一連の Node.js モジュールを使用して Amazon ID SES を検証および管理します。Node.js モジュールは、 SDKの JavaScript を使用して、SESクライアントクラスの次のメソッドを使用して E メールアドレスとドメインを検証します。

前提条件タスク

この例をセットアップして実行するには、まず次のタスクを完了する必要があります。

重要

これらの例は、 ECMAScript6 () を使用してクライアントサービスオブジェクトとコマンドをインポート/エクスポートする方法を示していますES6。

  • これには Node.js バージョン 13.x 以降が必要です。Node.js の最新バージョンをダウンロードしてインストールするには、「Node.js ダウンロード」を参照してください。

  • CommonJS 構文を使用する場合は、「JavaScript ES6/CommonJS 構文」を参照してください。

アイデンティティの一覧表示

この例では、Node.js モジュールを使用して、Amazon で使用する E メールアドレスとドメインを一覧表示します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"; // Create SES service object. const sesClient = new SESClient({ region: REGION }); export { sesClient };

このサンプルコードは、 にあります GitHub

ses_listidentities.js というファイル名で Node.js モジュールを作成します。必要なクライアントとパッケージのインストールを含め、前述のSDKように を設定します。

SES クライアントクラスの ListIdentitiesCommand メソッドに IdentityType とその他のパラメータを渡すオブジェクトを作成します。ListIdentitiesCommand メソッドを呼び出すには、Amazon SESサービスオブジェクトを呼び出し、パラメータオブジェクトを渡します。

返されるdataには、IdentityTypeパラメーターで指定されたドメインIDの配列が含まれます。

注記

置換 IdentityType ID タイプはEmailAddress「」または「ドメイン」です。

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

E メールアドレスアイデンティの検証

この例では、Node.js モジュールを使用して、Amazon で使用する E メール送信者を検証します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"; // Create SES service object. const sesClient = new SESClient({ region: REGION }); export { sesClient };

このサンプルコードは、 にあります GitHub

ses_verifyemailidentity.js というファイル名で Node.js モジュールを作成します。必要なクライアントとパッケージのダウンロードを含め、前述のSDKように を設定します。

SES クライアントクラスの VerifyEmailIdentityCommand メソッドに EmailAddress パラメータを渡すオブジェクトを作成します。VerifyEmailIdentityCommand メソッドを呼び出すには、パラメータを渡して Amazon SESクライアントサービスオブジェクトを呼び出します。

注記

置換 EMAIL_ADDRESS 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

ドメイン ID の検証

この例では、Node.js モジュールを使用して、Amazon で使用する E メールドメインを検証します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"; // Create SES service object. const sesClient = new SESClient({ region: REGION }); export { sesClient };

このサンプルコードは、 にあります GitHub

ses_verifydomainidentity.js というファイル名で Node.js モジュールを作成します。必要なクライアントとパッケージのインストールを含め、前述のSDKように を設定します。

SES クライアントクラスの VerifyDomainIdentityCommand メソッドに Domain パラメータを渡すオブジェクトを作成します。VerifyDomainIdentityCommand メソッドを呼び出すには、Amazon SESクライアントサービスオブジェクトを呼び出し、パラメータオブジェクトを渡します。

注記

この例では、必要な AWS Service V3 パッケージクライアント、V3 コマンドをインポートして使用し、非同期/待機パターンで sendメソッドを使用します。この例は、代わりに少し変更を加えてV2コマンドで作成できます。詳細については、「v3 コマンドの使用」を参照してください。

注記

置換 DOMAIN_NAME ドメイン名の 。

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

アイデンティティの削除

この例では、Node.js モジュールを使用して、Amazon で使用される E メールアドレスまたはドメインを削除します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"; // Create SES service object. const sesClient = new SESClient({ region: REGION }); export { sesClient };

このサンプルコードは、 にあります GitHub

ses_deleteidentity.js というファイル名で Node.js モジュールを作成します。必要なクライアントとパッケージのインストールを含め、前述のSDKように を設定します。

SES クライアントクラスの DeleteIdentityCommand メソッドに Identity パラメータを渡すオブジェクトを作成します。DeleteIdentityCommand メソッドを呼び出すには、Amazon SESクライアントサービスオブジェクトを呼び出すrequestための を作成し、パラメータを渡します。

注記

この例では、必要な AWS Service V3 パッケージクライアント、V3 コマンドをインポートして使用し、非同期/待機パターンで sendメソッドを使用します。この例は、代わりに少し変更を加えてV2コマンドで作成できます。詳細については、「v3 コマンドの使用」を参照してください。

注記

置換 IDENTITY_EMAIL 削除する 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