· 7 years ago · Aug 14, 2018, 09:20 AM
1pip install boto3
2
3import boto3
4from botocore.exceptions import ClientError
5
6SENDER = "Sender Name <sender@example.com>"
7RECIPIENT = "recipient@example.com"
8CONFIGURATION_SET = "ConfigSet"
9SUBJECT = "Amazon SES Test (SDK for Python)"
10BODY_TEXT = ("Test")
11BODY_HTML = """<html><head></head><body><h1>Test</h1></body></html>"""
12CHARSET = "UTF-8"
13
14ACCESS_KEY = 'foo'
15SECRET_KEY = 'foo'
16SESSION_TOKEN = 'foo'
17
18client = boto3.client(
19 'ses',
20 region_name="us-west-2",
21 aws_access_key_id=ACCESS_KEY,
22 aws_secret_access_key=SECRET_KEY,
23 aws_session_token=SESSION_TOKEN,
24)
25
26try:
27 response = client.send_email(
28 Destination={
29 'ToAddresses': [
30 RECIPIENT,
31 ],
32 },
33 Message={
34 'Body': {
35 'Html': {
36 'Charset': CHARSET,
37 'Data': BODY_HTML,
38 },
39 'Text': {
40 'Charset': CHARSET,
41 'Data': BODY_TEXT,
42 },
43 },
44 'Subject': {
45 'Charset': CHARSET,
46 'Data': SUBJECT,
47 },
48 },
49 Source=SENDER,
50 # If you are not using a configuration set, comment or delete the
51 # following line
52 ConfigurationSetName=CONFIGURATION_SET,
53 )
54# Display an error if something goes wrong.
55except ClientError as e:
56 print(e.response['Error']['Message'])
57else:
58 print("Email sent! Message ID:"),
59 print(response['MessageId'])