Created
August 7, 2015 07:00
-
-
Save nanvel/eed913ce5454d823d0f4 to your computer and use it in GitHub Desktop.
Send email with attachments using Amazon SES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] = '[email protected]' | |
msg['To'] = '[email protected]' | |
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