搭VerifyDomainIdentity配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

VerifyDomainIdentity配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用VerifyDomainIdentity

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

CLI
AWS CLI

透過 Amazon 驗證網域 SES

下列範例會使用 verify-domain-identity 命令來驗證網域:

aws ses verify-domain-identity --domain example.com

輸出:

{ "VerificationToken": "eoEmxw+YaYhb3h3iVJHuXMJXqeu1q1/wwmvjuEXAMPLE" }

若要完成網域驗證,您必須在網域DNS設定中新增包含傳回驗證 Token 的TXT記錄。如需詳細資訊,請參閱 Amazon 簡易電子郵件服務開發人員指南SES中的驗證 Amazon 網域。

JavaScript
SDK對於 JavaScript (3)
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import { VerifyDomainIdentityCommand } from "@aws-sdk/client-ses"; import { getUniqueName, postfix, } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; import { sesClient } from "./libs/sesClient.js"; /** * You must have access to the domain's DNS settings to complete the * domain verification process. */ const DOMAIN_NAME = postfix(getUniqueName("Domain"), ".example.com"); const createVerifyDomainIdentityCommand = () => { return new VerifyDomainIdentityCommand({ Domain: DOMAIN_NAME }); }; const run = async () => { const VerifyDomainIdentityCommand = createVerifyDomainIdentityCommand(); try { return await sesClient.send(VerifyDomainIdentityCommand); } catch (err) { console.log("Failed to verify domain.", err); return err; } };
Python
SDK對於 Python(肉毒桿菌 3)
注意

還有更多關於 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_domain_identity(self, domain_name): """ Starts verification of a domain identity. To complete verification, you must create a TXT record with a specific format through your DNS provider. For more information, see *Verifying a domain with Amazon SES* in the Amazon SES documentation: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-domain-procedure.html :param domain_name: The name of the domain to verify. :return: The token to include in the TXT record with your DNS provider. """ try: response = self.ses_client.verify_domain_identity(Domain=domain_name) token = response["VerificationToken"] logger.info("Got domain verification token for %s.", domain_name) except ClientError: logger.exception("Couldn't verify domain %s.", domain_name) raise else: return token