AWS Messaging & Targeting Blog

Scripting Amazon SES with Powershell – Attempts and Bounces

Did you know that you can interact with Amazon SES using Windows Powershell? To get started, download the AWS Tools for Windows Powershell and configure Powershell.

Let’s get your total deliveries and total bounces for the last two weeks. Powershell uses the GetSendStatistics Amazon SES API to get this data.

Here is the full script.

$stats=Get-SESSendStatistics
$attempts=0
$bounces=0
foreach ($x in $stats) 
{
    $attempts += $x.DeliveryAttempts;
    $bounces += $x.Bounces;
}
Write-Output "Attempts: " $attempts
Write-Output "Bounces: " $bounces
Write-Output $stats

The script invokes Get-SESSendStatistics to get your two-week sending history from SES. Get-SESSendStatistics returns a list, which is stored in $stats. The script then loops over each item in the list, aggregates the attempts and bounces, and displays the result.

When I run this script against my account, the output is:

Attempts:
176
Bounces:
3


Timestamp        : 2/5/2013 3:12:00 PM
DeliveryAttempts : 1
Bounces          : 0
Complaints       : 0
Rejects          : 0

Timestamp        : 1/31/2013 3:12:00 PM
DeliveryAttempts : 24
Bounces          : 1
Complaints       : 0
Rejects          : 0

Timestamp        : 1/31/2013 11:12:00 AM
DeliveryAttempts : 1
Bounces          : 0
Complaints       : 0
Rejects          : 0

Timestamp        : 1/31/2013 3:42:00 PM
DeliveryAttempts : 70
Bounces          : 0
Complaints       : 0
Rejects          : 0

Timestamp        : 1/31/2013 2:42:00 PM
DeliveryAttempts : 26
Bounces          : 0
Complaints       : 0
Rejects          : 0

Timestamp        : 1/31/2013 2:57:00 PM
DeliveryAttempts : 54
Bounces          : 2
Complaints       : 0
Rejects          : 0

You can use a variant of this script to store your attempt and bounce history into an internal monitoring system to evaluate your sending over time.

As always, we appreciate any feedback. Please post questions to the Amazon SES forum. Happy sending with Amazon SES and stay tuned for more!