Created
April 26, 2012 16:29
-
-
Save speric/2500792 to your computer and use it in GitHub Desktop.
Grab bounced emails from Sendgrid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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