Permalink
Browse files

Added support for sending raw messages

  • Loading branch information...
1 parent 7e855cf commit 5b9297c248522e0f125284f797d0a600b0c60857 @hmarr hmarr committed with Mitch Garnaat Jan 25, 2011
Showing with 46 additions and 0 deletions.
  1. +46 −0 boto/ses/__init__.py
View
@@ -24,7 +24,9 @@
from boto.exception import BotoServerError
import boto
import boto.jsonresponse
+
import urllib
+import base64
class SESConnection(AWSAuthConnection):
@@ -115,3 +117,47 @@ def send_email(self, source, subject, body, to_addresses, cc_addresses=None,
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
+
+ def send_raw_email(self, source, raw_message, destinations=None):
+ """
+ :type source: string
+ :param source: The sender's email address.
+
+ :type raw_message: string
+ :param raw_message: The raw text of the message. The client is
+ responsible for ensuring the following:
+
+ - Message must contain a header and a body, separated by a blank line.
+ - All required header fields must be present.
+ - Each part of a multipart MIME message must be formatted properly.
+ - MIME content types must be among those supported by Amazon SES.
+ Refer to the Amazon SES Developer Guide for more details.
+ - Content must be base64-encoded, if MIME requires it.
+
+ :type destinations: list of strings or string
+ :param destinations: A list of destinations for the message.
+
+ """
+ params = {
+ 'Action': 'SendRawEmail',
+ 'Source': source,
+ 'RawMessage.Data': base64.b64encode(raw_message),
+ }
+
+ self.build_list_params(params, destinations,
+ 'Destinations.member')
+
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
+ response = self.make_request('POST', '/', headers=headers,
+ data=urllib.urlencode(params))
+ body = response.read()
+ if response.status == 200:
+ e = boto.jsonresponse.Element()
+ h = boto.jsonresponse.XmlHandler(e, None)
+ h.parse(body)
+ return e
+ else:
+ boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s' % body)
+ raise self.ResponseError(response.status, response.reason, body)
+

0 comments on commit 5b9297c

Please sign in to comment.