AWS 文档 SDK 示例
将 VerifyEmailIdentity 与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 VerifyEmailIdentity。
操作示例是大型程序的代码摘录,必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文:
- .NET
-
- 适用于 .NET 的 SDK
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /// <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; }-
有关 API 详细信息,请参阅《适用于 .NET 的 AWS SDK API Reference》中的 VerifyEmailIdentity。
-
- C++
-
- SDK for C++
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 //! 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(); }-
有关 API 详细信息,请参阅《适用于 C++ 的 AWS SDK API Reference》中的 VerifyEmailIdentity。
-
- CLI
-
- AWS CLI
-
使用 Amazon SES 验证电子邮件地址
以下示例使用
verify-email-identity命令验证电子邮件地址:aws ses verify-email-identity --email-addressuser@example.com在使用 Amazon SES 发送电子邮件之前,您必须验证从中发送电子邮件的地址或域,以证明您拥有该地址或域。如果您尚未获得生产访问权限,则还需要验证所有收件电子邮件地址,Amazon SES 邮箱模拟器提供的电子邮件地址除外。
调用 verify-email-identity 后,该电子邮件地址将收到一封验证电子邮件。用户必须单击此电子邮件中的链接才能完成验证过程。
有关更多信息,请参阅《Amazon Simple Email Service 开发人员指南》中的“在 Amazon SES 中验证电子邮件地址”。
-
有关 API 详细信息,请参阅《AWS CLI Command Reference》中的 VerifyEmailIdentity
。
-
- JavaScript
-
- SDK for JavaScript (v3)
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 // 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; } };-
有关 API 详细信息,请参阅《适用于 JavaScript 的 AWS SDK API Reference》中的 VerifyEmailIdentity。
-
- Python
-
- 适用于 Python 的 SDK (Boto3)
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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-
有关 API 详细信息,请参阅《AWS SDK for Python (Boto3) API Reference》中的 VerifyEmailIdentity。
-
- Ruby
-
- 适用于 Ruby 的 SDK
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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-
有关 API 详细信息,请参阅《适用于 Ruby 的 AWS SDK API Reference》中的 VerifyEmailIdentity。
-