

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Membuat dan mengelola aturan email menggunakan Amazon SES API dan AWS SDK untuk PHP Versi 3
<a name="ses-rules"></a>

Selain mengirim email, Anda juga dapat menerima email dengan Amazon Simple Email Service (Amazon SES). Aturan tanda terima memungkinkan Anda menentukan apa yang Amazon SES lakukan dengan email yang diterimanya untuk alamat email atau domain yang Anda miliki. Aturan dapat mengirim email ke AWS layanan lain termasuk namun tidak terbatas pada Amazon S3, Amazon SNS, atau. AWS Lambda

Untuk selengkapnya, lihat [Mengelola kumpulan aturan tanda terima untuk Menerima Email Amazon SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-managing-receipt-rule-sets.html) dan [Mengelola Aturan Tanda Terima untuk Penerimaan Email Amazon SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-managing-receipt-rules.html).

Contoh berikut menunjukkan cara:
+ Buat aturan tanda terima yang ditetapkan menggunakan [CreateReceiptRuleSet](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#createreceiptruleset).
+ Buat aturan tanda terima menggunakan [CreateReceiptRule](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#createreceiptrule).
+ Jelaskan aturan tanda terima yang ditetapkan menggunakan [DescribeReceiptRuleSet](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#describereceiptruleset).
+ Jelaskan aturan tanda terima menggunakan [DescribeReceiptRule](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#describereceiptrule).
+ Buat daftar semua set aturan tanda terima menggunakan [ListReceiptRuleSets](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#listreceiptrulesets).
+ Perbarui aturan tanda terima menggunakan [UpdateReceiptRule](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#updatereceiptrule).
+ Hapus aturan tanda terima menggunakan [DeleteReceiptRule](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#deletereceiptrule).
+ Hapus aturan tanda terima yang ditetapkan menggunakan [DeleteReceiptRuleSet](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#deletereceiptruleset).

Semua kode contoh untuk AWS SDK untuk PHP tersedia [di sini GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code).

## Kredensial
<a name="examplecredentials"></a>

Sebelum menjalankan kode contoh, konfigurasikan AWS kredenal Anda, seperti yang dijelaskan dalam. [Mengautentikasi dengan AWS menggunakan AWS SDK untuk PHP Versi 3](credentials.md) Kemudian impor AWS SDK untuk PHP, seperti yang dijelaskan dalam[Menginstal AWS SDK untuk PHP Versi 3](getting-started_installation.md).

Untuk informasi selengkapnya tentang penggunaan Amazon SES, lihat [Panduan Pengembang Amazon SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/).

## Buat set aturan tanda terima
<a name="create-a-receipt-rule-set"></a>

Set aturan tanda terima berisi kumpulan aturan tanda terima. Anda harus memiliki setidaknya satu set aturan tanda terima yang terkait dengan akun Anda sebelum Anda dapat membuat aturan tanda terima. Untuk membuat set aturan tanda terima, berikan yang unik RuleSetName dan gunakan [CreateReceiptRuleSet](https://docs.aws.amazon.com/ses/latest/APIReference/API_CreateReceiptRuleSet.html)operasi.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$name = 'Rule_Set_Name';

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

## Buat aturan penerimaan
<a name="create-a-receipt-rule"></a>

Kontrol email masuk Anda dengan menambahkan aturan tanda terima ke set aturan tanda terima yang ada. Contoh ini menunjukkan cara membuat aturan tanda terima yang mengirim pesan masuk ke bucket Amazon S3, tetapi Anda juga dapat mengirim pesan ke Amazon SNS dan. AWS Lambda Untuk membuat aturan tanda terima, berikan aturan RuleSetName dan [CreateReceiptRule](https://docs.aws.amazon.com/ses/latest/APIReference/API_CreateReceiptRule.html)operasi.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$rule_name = 'Rule_Name';
$rule_set_name = 'Rule_Set_Name';
$s3_bucket = 'Bucket_Name';

try {
    $result = $SesClient->createReceiptRule([
        'Rule' => [
            'Actions' => [
                [
                    'S3Action' => [
                        'BucketName' => $s3_bucket,
                    ],
                ],
            ],
            'Name' => $rule_name,
            'ScanEnabled' => true,
            'TlsPolicy' => 'Optional',
            'Recipients' => ['<string>']
        ],
        'RuleSetName' =>  $rule_set_name,

     ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## Jelaskan set aturan tanda terima
<a name="describe-a-receipt-rule-set"></a>

Sekali per detik, kembalikan detail set aturan tanda terima yang ditentukan. Untuk menggunakan [DescribeReceiptRuleSet](https://docs.aws.amazon.com/ses/latest/APIReference/API_DescribeReceiptRuleSet.html)operasi, berikan RuleSetName.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$name = 'Rule_Set_Name';

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

## Jelaskan aturan tanda terima
<a name="describe-a-receipt-rule"></a>

Kembalikan detail aturan tanda terima yang ditentukan. Untuk menggunakan [DescribeReceiptRule](https://docs.aws.amazon.com/ses/latest/APIReference/API_DescribeReceiptRule.html)operasi, berikan RuleName dan RuleSetName.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$rule_name = 'Rule_Name';
$rule_set_name = 'Rule_Set_Name';

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

## Cantumkan semua set aturan tanda terima
<a name="list-all-receipt-rule-sets"></a>

Untuk mencantumkan kumpulan aturan tanda terima yang ada Akun AWS di bawah AWS Wilayah Anda saat ini, gunakan [ListReceiptRuleSets](https://docs.aws.amazon.com/ses/latest/APIReference/API_ListReceiptRuleSets.html)operasi.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

try {
    $result = $SesClient->listReceiptRuleSets();
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## Perbarui aturan tanda terima
<a name="update-a-receipt-rule"></a>

Contoh ini menunjukkan cara memperbarui aturan tanda terima yang mengirim pesan masuk ke suatu AWS Lambda fungsi, tetapi Anda juga dapat mengirim pesan ke Amazon SNS dan Amazon S3. Untuk menggunakan [UpdateReceiptRule](https://docs.aws.amazon.com/ses/latest/APIReference/API_UpdateReceiptRule.html)operasi, berikan aturan tanda terima baru dan RuleSetName.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$rule_name = 'Rule_Name';
$rule_set_name = 'Rule_Set_Name';
$lambda_arn = 'Amazon Resource Name (ARN) of the AWS Lambda function';
$sns_topic_arn = 'Amazon Resource Name (ARN) of the Amazon SNS topic';

try {
    $result = $SesClient->updateReceiptRule([
        'Rule' => [
            'Actions' => [
                'LambdaAction' => [
                    'FunctionArn' => $lambda_arn,
                    'TopicArn' => $sns_topic_arn,
                ],
            ],
            'Enabled' => true,
            'Name' => $rule_name,
            'ScanEnabled' => false,
            'TlsPolicy' => 'Require',
        ],
        'RuleSetName' => $rule_set_name,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## Hapus set aturan tanda terima
<a name="delete-a-receipt-rule-set"></a>

Hapus kumpulan aturan tanda terima tertentu yang saat ini tidak dinonaktifkan. Ini juga menghapus semua aturan tanda terima yang dikandungnya. Untuk menghapus set aturan tanda terima, berikan RuleSetName ke [DeleteReceiptRuleSet](https://docs.aws.amazon.com/ses/latest/APIReference/API_DeleteReceiptRuleSet.html)operasi.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$name = 'Rule_Set_Name';

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

## Hapus aturan tanda terima
<a name="delete-a-receipt-rule"></a>

Untuk menghapus aturan tanda terima yang ditentukan, berikan RuleName dan RuleSetName ke [DeleteReceiptRule](https://docs.aws.amazon.com/ses/latest/APIReference/API_DeleteReceiptRule.html)operasi.

 **Impor** 

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

use Aws\Exception\AwsException;
```

 **Kode Sampel** 

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

$rule_name = 'Rule_Name';
$rule_set_name = 'Rule_Set_Name';

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