文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
VerifyEmailIdentity
搭配 AWS SDK或 使用 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詳細資訊,請參閱 參考 VerifyEmailIdentity中的 。 AWS SDK for .NET API
-
- 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詳細資訊,請參閱 參考 VerifyEmailIdentity中的 。 AWS SDK for C++ API
-
- 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,電子郵件地址會收到驗證電子郵件。使用者必須按一下電子郵件中的連結,以完成驗證程序。
如需詳細資訊,請參閱Amazon Simple Email Service 開發人員指南SES中的在 Amazon 中驗證電子郵件地址。
-
如需API詳細資訊,請參閱 命令參考 VerifyEmailIdentity
中的 。 AWS CLI
-
- 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詳細資訊,請參閱 參考 VerifyEmailIdentity中的 。 AWS SDK for JavaScript API
-
- Python
-
- SDK for 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 SDK for Python (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 => e puts "Email not sent. Error message: #{e}" end
-
如需API詳細資訊,請參閱 參考 VerifyEmailIdentity中的 。 AWS SDK for Ruby API
-