Last active
March 16, 2020 11:05
-
-
Save cm-fujii/6dbf6e83e7708d40e0203edb8ffe2386 to your computer and use it in GitHub Desktop.
AWS-Lambda-Send-SES-Email-Sample
This file contains 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
import boto3 | |
from email.header import Header | |
SENDER_ADDRESS = 'no-reply@example.com' | |
SENDER_NAME = '私だ' | |
ses = boto3.client('ses', region_name='eu-west-1') | |
def lambda_handler(event, context): | |
to_address = 'hoge@example.com' | |
subject = 'テストメール' | |
body = 'これはテストメールです。' | |
send(to_address, subject, body) | |
def send(to_address, subject: str, body: str): | |
display_name = '{0}<{1}>'.format( | |
Header(SENDER_NAME, 'utf-8').encode(), | |
SENDER_ADDRESS | |
) | |
ses.send_email( | |
Source=display_name, | |
Destination={ | |
'ToAddresses': [to_address] | |
}, | |
Message={ | |
'Subject': { | |
'Data': subject | |
}, | |
'Body': { | |
'Text': { | |
'Data': body | |
} | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment