Created
June 3, 2011 17:35
-
-
Save pamelafox/1006753 to your computer and use it in GitHub Desktop.
Sendgrid Python Web API example
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 urllib2, urllib | |
import logging | |
def send_mail_sendgrid(from, to, subject, body): | |
base_url = 'https://sendgrid.com/api/mail.send.json' | |
params = { | |
'api_user': '[email protected]', | |
'api_key': 'yourpassword', | |
'from': from, | |
'to': to, | |
'subject': subject, | |
'text': body | |
} | |
encoded_params = urllib.urlencode(params) | |
url = '%s?%s' % (base_url, encoded_params) | |
try: | |
response = json.loads(urllib2.urlopen(url).read()) | |
if response['message'] == 'error': | |
logging.info('Error sending message: %s' % errors.join(',')) | |
except urllib2.HTTPError, e: | |
logging.info('Error sending message: %s, %s' % (e.code, e.read())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment