Email with attachments using SES

2,736 views
Skip to first unread message

Domingo Aguilera

unread,
Oct 31, 2011, 6:43:03 PM10/31/11
to boto-users
I wonder if it's possible to send email with attachments with ses.

Jeff Bauer

unread,
Oct 31, 2011, 8:40:15 PM10/31/11
to boto-...@googlegroups.com
On Mon, Oct 31, 2011 at 03:43:03PM -0700, Domingo Aguilera wrote:
> I wonder if it's possible to send email with attachments with
> ses.

Sure, no problem:

http://aws.amazon.com/ses/faqs/#24

Jeff Bauer
Rubicon, Inc.

Domingo Aguilera

unread,
Oct 31, 2011, 10:51:39 PM10/31/11
to boto-users
Any example on how to do this with boto?

Jeff Bauer

unread,
Oct 31, 2011, 11:31:43 PM10/31/11
to boto-...@googlegroups.com
Domingo,

We send out emails from our instances via an arrangement with AWS
that predates SES. However, even if we were to start with SES,
I'd probably still choose SendRawEmail and build our content with
the email tools in the standard Python library.

You can develop your code by sending email attachments to your
gmail account, for example, before deploying on SES. Or even a
test smtp server on your local machine, e.g.:

python /usr/lib/python2.6/smtpd.py -n -c DebuggingServer localhost:8025

-Jeff

Domingo Aguilera

unread,
Nov 1, 2011, 8:14:55 PM11/1/11
to boto-users
I've tried send_raw_email without success.

for example

from boto import connect_ses
c = connect_ses()
from turbomail.message import Message
m = Message( "sou...@acme.com", "desti...@acme.com", "test")
with open("README.txt", "rb") as fp:
m.attach( fp, "README.txt")
m.plain = "contents"
c.send_raw_email( "sou...@acme.com", str(m), "desti...@acme.com")

this gives an error like this ...

boto.exception.BotoServerError: BotoServerError: 400 Bad Request
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Nested group</Message>
</Error>
<RequestId>aae6d4ee-04e2-11e1-8a00-2bd94471c899</RequestId>
</ErrorResponse>

Domingo Aguilera

unread,
Nov 4, 2011, 1:03:51 PM11/4/11
to boto-users
Is anybody really sending mails with attachments from ses using boto/
python?

Mitchell Garnaat

unread,
Nov 4, 2011, 1:13:49 PM11/4/11
to boto-...@googlegroups.com
Hi -

You do need to use send_raw_email but you first have to create a properly formatted MIME Multipart payload to pass in to that method.  This:


has an example of constructing a MIME multipart message with the Python email module.

Mitch

On Fri, Nov 4, 2011 at 1:03 PM, Domingo Aguilera <domingo....@gmail.com> wrote:
Is anybody really sending mails with attachments from ses using boto/
python?

--
You received this message because you are subscribed to the Google Groups "boto-users" group.
To post to this group, send email to boto-...@googlegroups.com.
To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.


Domingo Aguilera

unread,
Nov 4, 2011, 3:04:56 PM11/4/11
to boto-users
I've tried this using turbomail

https://gist.github.com/1340186

and always have the same error as output..

<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Nested group</Message>
</Error>
<RequestId>cae7822d-0716-11e1-b764-8f9e43cf3a1b</RequestId>
</ErrorResponse>

This output is given with these fake addresses and with real ones.


On Nov 4, 11:13 am, Mitchell Garnaat <mi...@garnaat.com> wrote:
> Hi -
>
> You do need to use send_raw_email but you first have to create a properly
> formatted MIME Multipart payload to pass in to that method.  This:
>
> http://docs.python.org/library/email-examples.html
>
> has an example of constructing a MIME multipart message with the Python
> email module.
>
> Mitch
>
> On Fri, Nov 4, 2011 at 1:03 PM, Domingo Aguilera <domingo.aguil...@gmail.com

Steven Kurylo

unread,
Jul 16, 2012, 2:07:03 PM7/16/12
to boto-...@googlegroups.com
It has always worked fine for me....

import email
import boto.exception
from boto.ses.connection import SESConnection
to = 'f...@example.com'
m = email.mime.multipart.MIMEMultipart()
m['Subject'] = 'Test'
m['From'] = to
m['To'] = to

#Message body
part = email.mime.text.MIMEText('test file attached')
m.attach(part)

#Attachment
part = email.mime.text.MIMEText('contents of test file here')
part.add_header('Content-Disposition', 'attachment; filename=test.txt')
m.attach(part)

line = open('amazon.key').readlines()
a = SESConnection(aws_access_key_id=line[0].strip(),aws_secret_access_key=line[1].strip())
r = a.send_raw_email(source=m['From'], raw_message=m.as_string(),
destinations=m['To'])


On Mon, Jul 16, 2012 at 5:11 AM, murtaza52
<murtaza...@sevenolives.com> wrote:
> Hi,
>
> Was this issue solved ?
>
> We would also like to send SES emails with attachments. Any help will be
> appreciated.
>
> Thanks,
> Murtaza
> To view this discussion on the web visit
> https://groups.google.com/d/msg/boto-users/-/BZsG5h3E0noJ.
>
> To post to this group, send email to boto-...@googlegroups.com.
> To unsubscribe from this group, send email to
> boto-users+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/boto-users?hl=en.



--
Steven Kurylo
Reply all
Reply to author
Forward
0 new messages