Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created December 2, 2013 20:47
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 ghinch/7758701 to your computer and use it in GitHub Desktop.
Save ghinch/7758701 to your computer and use it in GitHub Desktop.
def _send(self, email_message):
from_email = sanitize_address(email_message.from_email, email_message.encoding)
recipients = [sanitize_address(addr, email_message.encoding)
for addr in email_message.recipients()]
try:
post_data = []
post_data.append(('to', (",".join(recipients)),))
post_data.append(('text', email_message.body,))
post_data.append(('subject', email_message.subject,))
post_data.append(('from', from_email,))
if email_message.alternatives:
for alt in email_message.alternatives:
if alt[1] == 'text/html':
post_data.append(('html', alt[0],))
break
if email_message.attachments:
for attachment in email_message.attachments:
post_data.append(('attachment', attachment[1],))
response = requests.post(self._api_url + "messages",
auth=("api", self._access_key),
files=post_data)
else:
response = requests.post(self._api_url + "messages",
auth=("api", self._access_key),
data=post_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment