Created
November 14, 2013 10:01
-
-
Save calpaterson/7464336 to your computer and use it in GitHub Desktop.
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
from datetime import datetime | |
import mandrill | |
def send_email(to_email, to_name, subject, message_text, from_email = '[email protected]', from_name='RPS Exemplar'): | |
#additional message parameters https://mandrillapp.com/api/docs/messages.JSON.html | |
api_key = _MANDRILL_APP_KEY_ | |
try: | |
mandrill_client = mandrill.Mandrill(api_key) | |
message = { | |
'auto_text': True, | |
'from_email': from_email, | |
'from_name': from_name, | |
'headers': { | |
'Reply-To': from_email | |
}, | |
'important': False, | |
'subject': subject, | |
'text': message_text, | |
'to': [{'email': to_email, | |
'name': to_name, | |
'type': 'to'}], | |
} | |
result = mandrill_client.messages.send(message=message, async=False, ip_pool='Main Pool') | |
except mandrill.Error, e: | |
# Mandrill errors are thrown as exceptions | |
print 'A mandrill error occurred: %s - %s' % (e.__class__, e) | |
# A mandrill error occurred: <class 'mandrill.UnknownSubaccountError'> - No subaccount exists with the id 'customer-123' | |
raise | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment