Managing email filters using the Amazon SES API and the Amazon SDK for PHP Version 3 - Amazon SDK for PHP
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Managing email filters using the Amazon SES API and the Amazon SDK for PHP Version 3

In addition to sending emails, you can also receive email with Amazon Simple Email Service (Amazon SES). An IP address filter enables you to optionally specify whether to accept or reject mail that originates from an IP address or range of IP addresses. For more information, see Managing IP Address Filters for Amazon SES Email Receiving.

The following examples show how to:

All the example code for the Amazon SDK for PHP is available here on GitHub.

Credentials

Before running the example code, configure your Amazon credentials, as described in Credentials. Then import the Amazon SDK for PHP, as described in Basic usage.

For more information about using Amazon SES, see the Amazon SES Developer Guide.

Create an email filter

To allow or block emails from a specific IP address, use the CreateReceiptFilter operation. Provide the IP address or range of addresses and a unique name to identify this filter.

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException;

Sample Code

$SesClient = new Aws\Ses\SesClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-2' ]); $filter_name = 'FilterName'; $ip_address_range = '10.0.0.1/24'; try { $result = $SesClient->createReceiptFilter([ 'Filter' => [ 'IpFilter' => [ 'Cidr' => $ip_address_range, 'Policy' => 'Block|Allow', ], 'Name' => $filter_name, ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

List all email filters

To list the IP address filters associated with your Amazon Web Services account in the current Amazon Region, use the ListReceiptFilters operation.

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException;

Sample Code

$SesClient = new Aws\Ses\SesClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-2' ]); try { $result = $SesClient->listReceiptFilters(); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Delete an email filter

To remove an existing filter for a specific IP address use the DeleteReceiptFilter operation. Provide the unique filter name to identify the receipt filter to delete.

If you need to change the range of addresses that are filtered, you can delete a receipt filter and create a new one.

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException;

Sample Code

$SesClient = new Aws\Ses\SesClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-2' ]); $filter_name = 'FilterName'; try { $result = $SesClient->deleteReceiptFilter([ 'FilterName' => $filter_name, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }