With boto3, you can send emails from Python via SES.
client = boto3.client('ses')
response = client.send_email(
Source='[email protected]',
Destination={
'ToAddresses': [
'[email protected]',
],
'CcAddresses': [
'[email protected]',
],
'BccAddresses': [
'[email protected]',
]
},
Message={
'Subject': {
'Data': 'SES Mail by Python',
'Charset': 'UTF-8'
},
'Body': {
'Text': {
'Data': 'This is text mail',
'Charset': 'UTF-8'
},
'Html': {
'Data': '<h1>This is Html Mail</h1>',
'Charset': 'UTF-8'
}
}
},
ReplyToAddresses=[
'[email protected]',
]
)
When executed, an email will be sent as shown below.
Tips
It seems that Message ['Body'] ['Text']
is not displayed when there is Message ['Body'] ['Html']
and the client can see HTML mail.
Use the address you put in Source
that has been authenticated by your SES account.
The permissions required to run are ses: SendEmail
.
Create a role like the one below and assign it to a Lambda or IAM user.
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"ses:SendEmail"
],
"Resource": [
"arn:aws:ses:*"
],
"Effect": "Allow"
}]
}
It seems that you can also process bounces, so if you are interested, please see below. http://boto3.readthedocs.io/en/latest/reference/services/ses.html#SES.Client.send_email
Recommended Posts