Use VerifyEmailIdentity with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use VerifyEmailIdentity with an AWS SDK or CLI

The following code examples show how to use VerifyEmailIdentity.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code examples:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Starts verification of an email identity. This request sends an email /// from Amazon SES to the specified email address. To complete /// verification, follow the instructions in the email. /// </summary> /// <param name="recipientEmailAddress">Email address to verify.</param> /// <returns>True if successful.</returns> public async Task<bool> VerifyEmailIdentityAsync(string recipientEmailAddress) { var success = false; try { var response = await _amazonSimpleEmailService.VerifyEmailIdentityAsync( new VerifyEmailIdentityRequest { EmailAddress = recipientEmailAddress }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("VerifyEmailIdentityAsync failed with exception: " + ex.Message); } return success; }
C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

//! Add an email address to the list of identities associated with this account and //! initiate verification. /*! \param emailAddress; The email address to add. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SES::verifyEmailIdentity(const Aws::String &emailAddress, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SES::SESClient sesClient(clientConfiguration); Aws::SES::Model::VerifyEmailIdentityRequest verifyEmailIdentityRequest; verifyEmailIdentityRequest.SetEmailAddress(emailAddress); Aws::SES::Model::VerifyEmailIdentityOutcome outcome = sesClient.VerifyEmailIdentity(verifyEmailIdentityRequest); if (outcome.IsSuccess()) { std::cout << "Email verification initiated." << std::endl; } else { std::cerr << "Error initiating email verification. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
CLI
AWS CLI

To verify an email address with Amazon SES

The following example uses the verify-email-identity command to verify an email address:

aws ses verify-email-identity --email-address user@example.com

Before you can send an email using Amazon SES, you must verify the address or domain that you are sending the email from to prove that you own it. If you do not have production access yet, you also need to verify any email addresses that you send emails to except for email addresses provided by the Amazon SES mailbox simulator.

After verify-email-identity is called, the email address will receive a verification email. The user must click on the link in the email to complete the verification process.

For more information, see Verifying Email Addresses in Amazon SES in the Amazon Simple Email Service Developer Guide.

JavaScript
SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

// Import required AWS SDK clients and commands for Node.js import { VerifyEmailIdentityCommand } from "@aws-sdk/client-ses"; import { sesClient } from "./libs/sesClient.js"; const EMAIL_ADDRESS = "name@example.com"; const createVerifyEmailIdentityCommand = (emailAddress) => { return new VerifyEmailIdentityCommand({ EmailAddress: emailAddress }); }; const run = async () => { const verifyEmailIdentityCommand = createVerifyEmailIdentityCommand(EMAIL_ADDRESS); try { return await sesClient.send(verifyEmailIdentityCommand); } catch (err) { console.log("Failed to verify email identity.", err); return err; } };
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class SesIdentity: """Encapsulates Amazon SES identity functions.""" def __init__(self, ses_client): """ :param ses_client: A Boto3 Amazon SES client. """ self.ses_client = ses_client def verify_email_identity(self, email_address): """ Starts verification of an email identity. This function causes an email to be sent to the specified email address from Amazon SES. To complete verification, follow the instructions in the email. :param email_address: The email address to verify. """ try: self.ses_client.verify_email_identity(EmailAddress=email_address) logger.info("Started verification of %s.", email_address) except ClientError: logger.exception("Couldn't start verification of %s.", email_address) raise
Ruby
SDK for Ruby
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

require 'aws-sdk-ses' # v2: require 'aws-sdk' # Replace recipient@example.com with a "To" address. recipient = 'recipient@example.com' # Create a new SES resource in the us-west-2 region. # Replace us-west-2 with the AWS Region you're using for Amazon SES. ses = Aws::SES::Client.new(region: 'us-west-2') # Try to verify email address. begin ses.verify_email_identity({ email_address: recipient }) puts "Email sent to #{recipient}" # If something goes wrong, display an error message. rescue Aws::SES::Errors::ServiceError => e puts "Email not sent. Error message: #{e}" end