-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathsesv2_hello.py
More file actions
77 lines (63 loc) · 2.44 KB
/
sesv2_hello.py
File metadata and controls
77 lines (63 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
Shows how to get started with Amazon SESv2 by listing email identities
associated with the account.
"""
import logging
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
# snippet-start:[python.example_code.sesv2.Hello]
def hello_sesv2(sesv2_client):
"""
Use the AWS SDK for Python (Boto3) to create an Amazon SESv2 client and
list the email identities in your account. This example uses the default
settings specified in your shared credentials and config files.
:param sesv2_client: A Boto3 SESv2 client object.
"""
print("Hello, Amazon SESv2! Let's list your email identities:\n")
identity_count = 0
next_token = None
try:
while True:
kwargs = {"PageSize": 20}
if next_token:
kwargs["NextToken"] = next_token
response = sesv2_client.list_email_identities(**kwargs)
identities = response.get("EmailIdentities", [])
for identity in identities:
identity_count += 1
identity_name = identity.get("IdentityName", "Unknown")
identity_type = identity.get("IdentityType", "Unknown")
verification_status = identity.get(
"VerificationStatus", "Unknown"
)
sending_enabled = identity.get("SendingEnabled", False)
print(
f" Identity: {identity_name}"
f" Type: {identity_type}"
f" Status: {verification_status}"
f" Sending: {'Enabled' if sending_enabled else 'Disabled'}"
)
next_token = response.get("NextToken")
if not next_token:
break
if identity_count == 0:
print(
"No email identities found. "
"Use CreateEmailIdentity to add one."
)
else:
print(f"\nFound {identity_count} email identity(ies).")
except ClientError as err:
logger.error(
"Couldn't list email identities. Here's why: %s: %s",
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
# snippet-end:[python.example_code.sesv2.Hello]
if __name__ == "__main__":
hello_sesv2(boto3.client("sesv2"))