CreateReceiptRuleSet 搭配 a AWS SDK 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

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

CreateReceiptRuleSet 搭配 a AWS SDK 使用

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

C++
C++ 的 SDK
注意

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

//! Create an Amazon Simple Email Service (Amazon SES) receipt rule set. /*! \param ruleSetName: The name of the rule set. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SES::createReceiptRuleSet(const Aws::String &ruleSetName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SES::SESClient sesClient(clientConfiguration); Aws::SES::Model::CreateReceiptRuleSetRequest createReceiptRuleSetRequest; createReceiptRuleSetRequest.SetRuleSetName(ruleSetName); Aws::SES::Model::CreateReceiptRuleSetOutcome outcome = sesClient.CreateReceiptRuleSet( createReceiptRuleSetRequest); if (outcome.IsSuccess()) { std::cout << "Successfully created receipt rule set." << std::endl; } else { std::cerr << "Error creating receipt rule set. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
JavaScript
SDK for JavaScript (v3)
注意

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

import { CreateReceiptRuleSetCommand } from "@aws-sdk/client-ses"; import { sesClient } from "./libs/sesClient.js"; import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; const RULE_SET_NAME = getUniqueName("RuleSetName"); const createCreateReceiptRuleSetCommand = (ruleSetName) => { return new CreateReceiptRuleSetCommand({ RuleSetName: ruleSetName }); }; const run = async () => { const createReceiptRuleSetCommand = createCreateReceiptRuleSetCommand(RULE_SET_NAME); try { return await sesClient.send(createReceiptRuleSetCommand); } catch (err) { console.log("Failed to create receipt rule set", err); return err; } };
Python
Python 的 SDK (Boto3)
注意

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

class SesReceiptHandler: """Encapsulates Amazon SES receipt handling functions.""" def __init__(self, ses_client, s3_resource): """ :param ses_client: A Boto3 Amazon SES client. :param s3_resource: A Boto3 Amazon S3 resource. """ self.ses_client = ses_client self.s3_resource = s3_resource def create_receipt_rule_set(self, rule_set_name): """ Creates an empty rule set. Rule sets contain individual rules and can be used to organize rules. :param rule_set_name: The name to give the rule set. """ try: self.ses_client.create_receipt_rule_set(RuleSetName=rule_set_name) logger.info("Created receipt rule set %s.", rule_set_name) except ClientError: logger.exception("Couldn't create receipt rule set %s.", rule_set_name) raise
  • 如需 API 詳細資訊,請參閱 CreateReceiptRuleSet AWS SDK for Python (Boto3) Word 參考中的 API