awscliからSESでメールを送信する

send_email関数でメールを送信する。

http://boto3.readthedocs.io/en/latest/reference/services/ses.html

# -*- coding: utf-8 -*-

import boto3
from boto3.session import Session

FROM_ADDRESS = "hoge@example.com"
TO_ADDRESS = "huga@example2.com"
SUBJECT = "私はテストメールです"
CHARSET = "UTF-8"
BODY = "私はテストメールです。こんにちは。"

try:
    session = Session(profile_name='ses')
    client = session.client('ses')
    response = client.send_email(
        Source=FROM_ADDRESS,
        Destination={
            'ToAddresses': [
                TO_ADDRESS,
            ]
        },
        Message={
            'Subject': {
                'Data': SUBJECT,
                'Charset': CHARSET
            },
            'Body': {
                'Text': {
                    'Data': BODY,
                    'Charset': CHARSET
                }
            }
        },
        ReplyToAddresses=[
            FROM_ADDRESS,
        ]
    )
    print response
except Exception as e:
    print "********** exception occurs *********"
    print "type: " + str(type(e))
    print "message: " + e.message