Skip to content

Instantly share code, notes, and snippets.

@nanvel
Created August 7, 2015 07:00
Show Gist options
  • Save nanvel/eed913ce5454d823d0f4 to your computer and use it in GitHub Desktop.
Save nanvel/eed913ce5454d823d0f4 to your computer and use it in GitHub Desktop.
Send email with attachments using Amazon SES
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import botocore.session
if __name__ == '__main__':
session = botocore.session.get_session()
ses = session.get_service('ses')
operation = ses.get_operation('SendRawEmail')
endpoint = ses.get_endpoint('us-west-2')
msg = MIMEMultipart()
msg['Subject'] = 'Weekly report'
msg['From'] = 'admin@mysite.com'
msg['To'] = 'iam@gmail.com'
part = MIMEText('Here is the data You requested for.')
msg.attach(part)
part = MIMEApplication(open('./test.jpg', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename='image.jpg')
msg.attach(part)
print operation.call(endpoint=endpoint, RawMessage={
'Data': msg.as_string()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment