Python Example

Python script examples covering these Email API functions:
(1) Get Email Sent: retrieve information about all emails sent during a given period of time.
(2) Send Mail: send an email to a given address and print the approved senders on your screen.
(3) Create An Approved Sender: create a new approved sender for your Email account.

Get Email Sent Example

{
/* ==========================================================
* Dyn's Email Delivery RESTful API
* Revised: January 31, 2014
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Dyn, Inc. provides this sample merely as an example of
* how to use the Email Delivery REST API via Python.
* While we will endeavor to keep the sample updated as the
* API is enhanced, it is provided "as-is," without express
* or implied warranty. In no event shall Dyn, Inc. be held
* liable for any damages arising from the use of this code.
*
* ======================================================= */
#This script was built using Python version 2.7.2.
#This script relies on using the Python library called 'requests'.
#You can find this library at docs.python-requests.org
#Install the requests library prior to using this script
import requests
#Your api key is found or generated on the integration tab in the Email Delivery portal
api_key = "replace these words between the quotation marks with your api key" # my api key
def get_emailssent():
my_params = {
"apikey" : api_key,
"starttime" : "replace with your start date and time based on ISO 8601 format",
"endtime" : "replace with your end date and time based on ISO 8601 format",
}
#By printing r.text, you will get all of the information available for all emails sent
#during the identified time period. You can also add a direction to save the text
#to a file.
r = requests.get('http://email.api.dynect.net/rest/json/reports/sent', params=my_params)
print r.text
print get_emailssent()
}