Skip to content

Instantly share code, notes, and snippets.

@Arunmainthan
Last active November 20, 2020 09:14
Show Gist options
  • Save Arunmainthan/ee2eb6e53db27e0e2646c0c947477416 to your computer and use it in GitHub Desktop.
Save Arunmainthan/ee2eb6e53db27e0e2646c0c947477416 to your computer and use it in GitHub Desktop.
Send Email via SES
from __future__ import print_function
import boto3
import json
import decimal
from datetime import datetime
from boto3.dynamodb.conditions import Key, Attr
from botocore.exceptions import ClientError
ses = boto3.client(
'ses',
region_name = 'us-east-1',
endpoint_url = 'https://email.us-east-1.amazonaws.com'
)
BODY_HTML = """<html>
<head></head>
<body>
<h1>Amazon SES Test (SDK for Python)</h1>
<p>This email was sent with
<a href='https://aws.amazon.com/ses/'>Amazon SES</a> using the
<a href='https://aws.amazon.com/sdk-for-python/'>
AWS SDK for Python (Boto)</a>.</p>
</body>
</html>
"""
CHARSET = "UTF-8"
SUBJECT = "Amazon SES Test (SDK for Python)"
# The email body for recipients with non-HTML email clients.
BODY_TEXT = ("Amazon SES Test (Python)\r\n"
"This email was sent with Amazon SES using the "
"AWS SDK for Python (Boto)."
)
try:
response = ses.send_email(
Destination = {
'ToAddresses': [
'arunm0731@gmail.com'
],
},
Message = {
'Body': {
'Html': {
'Charset': CHARSET,
'Data': BODY_HTML
},
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT
}
},
Source = 'username@example.com'
)
except ClientError as e:
print(e)
else:
print('Email sent! Message ID:'),
print(response['MessageId'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment