Skip to content

Instantly share code, notes, and snippets.

@jg75
Last active March 28, 2016 18:39
Show Gist options
  • Save jg75/f12b3577e99057d099cd to your computer and use it in GitHub Desktop.
Save jg75/f12b3577e99057d099cd to your computer and use it in GitHub Desktop.
import boto3
def print_status(ses_client, identity):
response = ses_client.list_identities()
identities = response['Identities']
response = ses_client.list_verified_email_addresses()
verified_email_addresses = response['VerifiedEmailAddresses']
if identity in identities:
print("%s is recognized" % identity)
else:
print("%s is not recognized" % identity)
if identity in verified_email_addresses:
print("%s is verified" % identity)
else:
response = ses_client.get_identity_verification_attributes(
Identities=[identity]
)
verification_attributes = response['VerificationAttributes']
status = verification_attributes[identity]['VerificationStatus']
print("verification for %s is %s" % (identity, status))
if __name__ == '__main__':
identity = '[email protected]'
ses_client = boto3.client('ses')
waiter = ses_client.get_waiter('identity_exists')
message = {
'Subject': {
'Data': 'Test Message'
},
'Body': {
'Text': {
'Data': 'This is a test'
}
},
}
# Delete the identity to clear its verification status
ses_client.delete_identity(Identity=identity)
# Resend email verification
ses_client.verify_email_identity(EmailAddress=identity)
# Print identity verification status
print_status(ses_client, identity)
# Wait for the identity to exist
waiter.wait(Identities=[identity])
# Print identity verification status
print_status(ses_client, identity)
# Send an email to myself from myself
ses_client.send_email(
Source='[email protected]',
Destination={'ToAddresses': [identity]},
Message=message
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment