Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Amazon Simple Email Service client in Python
Python
tree: 7a215ad5b4

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.mkd
ses.py

README.mkd

ses.py: Amazon Simple Email Service API client

SES API version: 2010-12-01

Python Usage

Initialization:

>>> from ses improt SES, SESError
>>> ses = SES(key_id='YOUR ACCESS KEY ID', key='YOUR SECRET KEY')

Get sending quota:

>>> ses.quota
{'Max24HourSend': 1000, 'SentLast24Hours': 0, 'MaxSendRate': 1}

Get sending statistics:

>>> ses.stats
[{'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 2, 43), 'DeliveryAttempts': 2, 'Bounces': 1, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 2, 58), 'DeliveryAttempts': 1, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 3, 43), 'DeliveryAttempts': 9, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 3, 58), 'DeliveryAttempts': 6, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 4, 28), 'DeliveryAttempts': 2, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 5, 28), 'DeliveryAttempts': 2, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 7, 43), 'DeliveryAttempts': 1, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 8, 28), 'DeliveryAttempts': 3, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 13, 8, 58), 'DeliveryAttempts': 2, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 14, 2, 13), 'DeliveryAttempts': 6, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 14, 2, 28), 'DeliveryAttempts': 1, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 14, 2, 43), 'DeliveryAttempts': 6, 'Bounces': 0, 'Rejects': 0},
 {'Complaints': 0, 'Timestamp': datetime.datetime(2011, 8, 14, 3, 28), 'DeliveryAttempts': 1, 'Bounces': 0, 'Rejects': 0}]

timestamp is seconds since UNIX epoch in GMT/UTC. Every point represents the sending statistics during a 15-minute interval.

Get verified email addresses:

>>> ses.verified
[u'steve@example.com', u'larry@example.com']

Verify an email address:

>>> ses.verify('noreply@example.com')
{'RequestId': u'0f7297f3-c764-11e0-b6d0-273d09173b49'}

Delete a verified email address:

>>> ses.delete('noreply@example.com')
{'RequestId': u'36b0fb55-c764-11e0-ac10-2114a1a1f8e9'}

Send an email:

>>> ses.send(source    = 'norely@example.com',
...          to        = ['john@example.com', 'kate@example.com'],
...          subject   = 'This is a test message',
...          text_body = 'Message body in plain text',
...          html_body = 'Message body in HTML')
{'MessageId': u'00000131ce811456-6d32754c-8e68-4efc-9026-8c00518d901e-000000',
 'RequestId': u'a5aa67d0-c764-11e0-9f8f-3da8fc215a7e'}

Sending raw emails is not implemented yet.

All actions listed above will block while waiting for response from Amazon SES. All actions will raise SESError in case of error.

Command Line Usage

ses.py also provides command line interface, here is its help message:

ses.py [action] -k [credentials file] [args]

Example
-------
1. Sending email:

    echo "email text body" | ses.py send -k [credentials file] -f from_addr -t [to_addr1,to_addr2,...] -c [cc_addr1,cc_addr2,...] -b [bcc_addr1,bcc_addr2,...] -s "email subject" 


2. Get send quota:

    ses.py quota -k [credentials file]


3. Get send statistics:

    ses.py stats -k [credentials file]


4. Get verified email addresses:

    ses.py verified -k [credentials file]


5. Verify email addreses:

    ses.py verify -k [credentials file] [addr1,addr2,...]


6. Delete verified email addresses:

    ses.py delete -k [credentials file] [addr1,addr2,...]


Credentials file example
------------------------

    AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX
    AWSSecretKey=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
Something went wrong with that request. Please try again.