Skip to content

Instantly share code, notes, and snippets.

@speric
Created April 26, 2012 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speric/2500792 to your computer and use it in GitHub Desktop.
Save speric/2500792 to your computer and use it in GitHub Desktop.
Grab bounced emails from Sendgrid
import tornado.options
import urllib2
import json
from tornado.options import define, options
if __name__ == "__main__":
define("username", help="Your Sendgrid username (usually an email address)")
define("password", help="Your Sendgrid password")
tornado.options.parse_command_line()
password = options.password
username = options.username
if username is None or password is None:
raise Exception("username and password are both required")
url = "https://sendgrid.com/api/bounces.get.json?api_user=%s&api_key=%s" % (username, password)
response = urllib2.urlopen(url)
sendgrid_json = json.load(response)
response.close()
for bounce in sendgrid_json:
print "%s:%s" % (bounce['email'], bounce['reason'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment