CreateReceiptRuleSet搭配使用 AWS SDK - AWS SDK代码示例

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

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

CreateReceiptRuleSet搭配使用 AWS SDK

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

C++
SDK对于 C++
注意

还有更多相关信息 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对于 JavaScript (v3)
注意

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

Python
SDK适用于 Python (Boto3)
注意

还有更多相关信息 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