Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
send PDF attachment with boto and SES
''' quick example showing how to attach a pdf to multipart messages
and then send them from SES via boto
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import boto
# via
msg = MIMEMultipart()
msg['Subject'] = 'weekly report'
msg['From'] = ''
msg['To'] = ''
# what a recipient sees if they don't use an email reader
msg.preamble = 'Multipart message.\n'
# the message body
part = MIMEText('Howdy -- here is the data from last week.')
# the attachment
part = MIMEApplication(open('/tmp/weekly.pdf', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename='weekly.pdf')
# connect to SES
connection = boto.connect_ses(aws_access_key_id='ID123'
, aws_access_key_secret='secret456')
# and send the message
result = connection.send_raw_email(msg.as_string()
, source=msg['From']
, destinations=[msg['To']])
print result
Copy link

soulfly commented Aug 5, 2015

should be 'aws_secret_access_key', not 'aws_access_key_secret'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment