Verwenden Sie es CreateReceiptRule mit einem oder AWS SDK CLI - AWS SDK-Codebeispiele

Weitere AWS SDK Beispiele sind im Repo AWS Doc SDK Examples GitHub verfügbar.

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Verwenden Sie es CreateReceiptRule mit einem oder AWS SDK CLI

Die folgenden Codebeispiele zeigen, wie man es benutztCreateReceiptRule.

C++
SDKfür C++
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

//! Create an Amazon Simple Email Service (Amazon SES) receipt rule. /*! \param receiptRuleName: The name for the receipt rule. \param s3BucketName: The name of the S3 bucket for incoming mail. \param s3ObjectKeyPrefix: The prefix for the objects in the S3 bucket. \param ruleSetName: The name of the rule set where the receipt rule is added. \param recipients: Aws::Vector of recipients. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SES::createReceiptRule(const Aws::String &receiptRuleName, const Aws::String &s3BucketName, const Aws::String &s3ObjectKeyPrefix, const Aws::String &ruleSetName, const Aws::Vector<Aws::String> &recipients, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SES::SESClient sesClient(clientConfiguration); Aws::SES::Model::CreateReceiptRuleRequest createReceiptRuleRequest; Aws::SES::Model::S3Action s3Action; s3Action.SetBucketName(s3BucketName); s3Action.SetObjectKeyPrefix(s3ObjectKeyPrefix); Aws::SES::Model::ReceiptAction receiptAction; receiptAction.SetS3Action(s3Action); Aws::SES::Model::ReceiptRule receiptRule; receiptRule.SetName(receiptRuleName); receiptRule.WithRecipients(recipients); Aws::Vector<Aws::SES::Model::ReceiptAction> receiptActionList; receiptActionList.emplace_back(receiptAction); receiptRule.SetActions(receiptActionList); createReceiptRuleRequest.SetRuleSetName(ruleSetName); createReceiptRuleRequest.SetRule(receiptRule); auto outcome = sesClient.CreateReceiptRule(createReceiptRuleRequest); if (outcome.IsSuccess()) { std::cout << "Successfully created receipt rule." << std::endl; } else { std::cerr << "Error creating receipt rule. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
JavaScript
SDKfür JavaScript (v3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

import { CreateReceiptRuleCommand, TlsPolicy } 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 RULE_NAME = getUniqueName("RuleName"); const S3_BUCKET_NAME = getUniqueName("S3BucketName"); const createS3ReceiptRuleCommand = ({ bucketName, emailAddresses, name, ruleSet, }) => { return new CreateReceiptRuleCommand({ Rule: { Actions: [ { S3Action: { BucketName: bucketName, ObjectKeyPrefix: "email", }, }, ], Recipients: emailAddresses, Enabled: true, Name: name, ScanEnabled: false, TlsPolicy: TlsPolicy.Optional, }, RuleSetName: ruleSet, // Required }); }; const run = async () => { const s3ReceiptRuleCommand = createS3ReceiptRuleCommand({ bucketName: S3_BUCKET_NAME, emailAddresses: ["email@example.com"], name: RULE_NAME, ruleSet: RULE_SET_NAME, }); try { return await sesClient.send(s3ReceiptRuleCommand); } catch (err) { console.log("Failed to create S3 receipt rule.", err); throw err; } };
  • APIEinzelheiten finden Sie CreateReceiptRuleunter AWS SDK for JavaScript APIReferenz.

Python
SDKfür Python (Boto3)
Anmerkung

Es gibt noch mehr dazu. GitHub Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

Erstellen Sie einen Amazon S3 S3-Bucket, in dem Amazon Kopien eingehender E-Mails ablegen SES kann, und erstellen Sie eine Regel, die eingehende E-Mails für eine bestimmte Empfängerliste in den Bucket kopiert.

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_bucket_for_copy(self, bucket_name): """ Creates a bucket that can receive copies of emails from Amazon SES. This includes adding a policy to the bucket that grants Amazon SES permission to put objects in the bucket. :param bucket_name: The name of the bucket to create. :return: The newly created bucket. """ allow_ses_put_policy = { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSESPut", "Effect": "Allow", "Principal": {"Service": "ses.amazonaws.com"}, "Action": "s3:PutObject", "Resource": f"arn:aws:s3:::{bucket_name}/*", } ], } bucket = None try: bucket = self.s3_resource.create_bucket( Bucket=bucket_name, CreateBucketConfiguration={ "LocationConstraint": self.s3_resource.meta.client.meta.region_name }, ) bucket.wait_until_exists() bucket.Policy().put(Policy=json.dumps(allow_ses_put_policy)) logger.info("Created bucket %s to receive copies of emails.", bucket_name) except ClientError: logger.exception("Couldn't create bucket to receive copies of emails.") if bucket is not None: bucket.delete() raise else: return bucket def create_s3_copy_rule( self, rule_set_name, rule_name, recipients, bucket_name, prefix ): """ Creates a rule so that all emails received by the specified recipients are copied to an Amazon S3 bucket. :param rule_set_name: The name of a previously created rule set to contain this rule. :param rule_name: The name to give the rule. :param recipients: When an email is received by one of these recipients, it is copied to the Amazon S3 bucket. :param bucket_name: The name of the bucket to receive email copies. This bucket must allow Amazon SES to put objects into it. :param prefix: An object key prefix to give the emails copied to the bucket. """ try: self.ses_client.create_receipt_rule( RuleSetName=rule_set_name, Rule={ "Name": rule_name, "Enabled": True, "Recipients": recipients, "Actions": [ { "S3Action": { "BucketName": bucket_name, "ObjectKeyPrefix": prefix, } } ], }, ) logger.info( "Created rule %s to copy mail received by %s to bucket %s.", rule_name, recipients, bucket_name, ) except ClientError: logger.exception("Couldn't create rule %s.", rule_name) raise
  • APIEinzelheiten finden Sie unter CreateReceiptRulePython (Boto3) API -Referenz.AWS SDK