与 AWS SDK或VerifyEmailIdentity一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或VerifyEmailIdentity一起使用 CLI

以下代码示例演示如何使用 VerifyEmailIdentity

操作示例是大型程序的代码摘录,必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文:

.NET
AWS SDK for .NET
注意

还有更多相关信息 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详细信息,请参阅 “AWS SDK for .NET API参考 VerifyEmailIdentity” 中的。

C++
SDK对于 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详细信息,请参阅 “AWS SDK for C++ API参考 VerifyEmailIdentity” 中的。

CLI
AWS CLI

向 Amazon 验证电子邮件地址 SES

以下示例使用 verify-email-identity 命令验证电子邮件地址:

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

在使用 Amazon 发送电子邮件之前SES,您必须验证发送电子邮件的地址或域名,以证明您拥有该电子邮件。如果您还没有生产访问权限,则还需要验证除Amazon SES 邮箱模拟器提供的电子邮件地址之外的所有电子邮件地址。

接 verify-email-identity 到电话后,该电子邮件地址将收到一封验证电子邮件。用户必须单击此电子邮件中的链接才能完成验证过程。

有关更多信息,请参阅《亚马逊简单电子邮件服务开发者指南》SES中的在亚马逊中验证电子邮件地址。

JavaScript
SDK对于 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详细信息,请参阅 “AWS SDK for JavaScript API参考 VerifyEmailIdentity” 中的。

Python
SDK适用于 Python (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详细信息,请参阅VerifyEmailIdentity中的 AWS SDKPython (Boto3) API 参考。

Ruby
SDK对于 Ruby
注意

还有更多相关信息 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 => error puts "Email not sent. Error message: #{error}" end
  • 有关API详细信息,请参阅 “AWS SDK for Ruby API参考 VerifyEmailIdentity” 中的。