

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

# Amazon SES API および AWS SDK for PHP バージョン 3 を使用した送信者の認証
<a name="ses-sender-policy"></a>

お客様の代わりに別の AWS アカウント、AWS Identity and Access Management ユーザー、または AWS サービスが Amazon Simple Email Service (Amazon SES) を介して E メールを送信できるようにするには、送信認可ポリシーを作成します。これは、お客様が所有しているアイデンティティにアタッチする JSON ドキュメントです。

このポリシーには、そのアイデンティティでの送信を許可するユーザーとその条件が明示的にリストされます。お客様とポリシーでアクセス許可を明示的に付与したエンティティ以外のすべての送信者は、E メールの送信が許可されません。アイデンティティにはポリシーをアタッチしないことも、1 つまたは複数のポリシーをアタッチすることもできます。さらに、複数のステートメントを含む 1 つのポリシーを作成して、複数のポリシーの効果を持たせることもできます。

詳細については、「[Amazon SES での送信承認の使用](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization.html)」を参照してください。

以下の例では、次の方法を示しています。
+ [PutIdentityPolicy](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#createidentitypolicy) を使用して承認済み送信者を作成する。
+ [GetIdentityPolicies](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#getidentitypolicies) を使用して承認済み送信者のポリシーを取得する。
+ [ListIdentityPolicies](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#listidentitypolicies) を使用して承認済み送信者をリストする。
+ [DeleteIdentityPolicy](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#deleteidentitypolicy) を使用して承認済み送信者のアクセス許可を取り消す。

AWS SDK for PHP 用のすべてのサンプルコードは [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code) で入手できます。

## 認証情報
<a name="examplecredentials"></a>

サンプルコードを実行する前に、AWS の認証情報を設定します ([AWS SDK for PHP バージョン 3 AWS を使用した での認証](credentials.md) を参照)。AWS SDK for PHP からのインポート ([AWS SDK for PHP バージョン 3 のインストール](getting-started_installation.md) を参照)。

Amazon SES の使用の詳細については、「[Amazon SES デベロッパーガイド](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/)」を参照してください。

## 承認済み送信者を作成する
<a name="create-an-authorized-sender"></a>

別の AWS アカウント がお客様の代わりに E メールを送信することを承認するには、アイデンティティポリシーを使用し、確認済みの E メールアドレスまたはドメインから E メールを送信する認可を追加または更新します。アイデンティティポリシーを作成するには、[PutIdentityPolicy](https://docs.aws.amazon.com/ses/latest/APIReference/API_PutIdentityPolicy.html) オペレーションを使用します。

 **インポート**。

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
```

 **サンプルコード** 

```
$SesClient = new SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-1'
]);

$identity = "arn:aws:ses:us-east-1:123456789012:identity/example.com";
$other_aws_account = "0123456789";
$policy = <<<EOT
{
  "Id":"ExampleAuthorizationPolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement":[
    {
      "Sid":"AuthorizeAccount",
      "Effect":"Allow",
      "Resource":"$identity",
      "Principal":{
        "AWS":[ "$other_aws_account" ]
      },
      "Action":[
        "SES:SendEmail",
        "SES:SendRawEmail"
      ]
    }
  ]
}
EOT;
$name = "policyName";

try {
    $result = $SesClient->putIdentityPolicy([
        'Identity' => $identity,
        'Policy' => $policy,
        'PolicyName' => $name,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 承認済み送信者のポリシーを取得する
<a name="retrieve-polices-for-an-authorized-sender"></a>

特定の E メールアイデンティティまたはドメインアイデンティティに関連付けられている送信承認ポリシーを返します。指定された E メールアドレスまたはドメインの送信承認を取得するには、[GetIdentityPolicy](https://docs.aws.amazon.com/ses/latest/APIReference/API_GetIdentityPolicy.html) オペレーションを使用します。

 **インポート**。

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
```

 **サンプルコード** 

```
$SesClient = new SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-1'
]);

$identity = "arn:aws:ses:us-east-1:123456789012:identity/example.com";
$policies = ["policyName"];

try {
    $result = $SesClient->getIdentityPolicies([
        'Identity' => $identity,
        'PolicyNames' => $policies,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 承認済み送信者をリストする
<a name="list-authorized-senders"></a>

現在の AWS リージョンの特定の E メールアイデンティティまたはドメインアイデンティティに関連付けられている送信認可ポリシーをリストするには、[ListIdentityPolicies](https://docs.aws.amazon.com/ses/latest/APIReference/API_ListIdentityPolicies.html) オペレーションを使用します。

 **インポート**。

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
```

 **サンプルコード** 

```
$SesClient = new SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-1'
]);

$identity = "arn:aws:ses:us-east-1:123456789012:identity/example.com";

try {
    $result = $SesClient->listIdentityPolicies([
        'Identity' => $identity,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 承認済み送信者のアクセス許可を取り消す
<a name="revoke-permission-for-an-authorized-sender"></a>

別の AWS アカウント が E メールアイデンティティまたはドメインアイデンティティを持つ E メールを送信する送信認可を削除するには、[DeleteIdentityPolicy](https://docs.aws.amazon.com/ses/latest/APIReference/API_DeleteIdentityPolicy.html) オペレーションを使用して関連付けられたアイデンティティポリシーを削除します。

 **インポート**。

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
```

 **サンプルコード** 

```
$SesClient = new SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-1'
]);

$identity = "arn:aws:ses:us-east-1:123456789012:identity/example.com";
$name = "policyName";

try {
    $result = $SesClient->deleteIdentityPolicy([
        'Identity' => $identity,
        'PolicyName' => $name,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```