Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Membuat filter tanda terima Amazon SES menggunakanAWS SDK
Contoh kode berikut ini menunjukkan cara membuat filter penerimaan penerimaan penerimaan Amazon SES SES.
- JavaScript
-
- SDK for JavaScript (v3)
-
catatan Masih ada lagi GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di AWSCode Examples Repository
. import { CreateReceiptFilterCommand, ReceiptFilterPolicy, } from "@aws-sdk/client-ses"; import { sesClient } from "./libs/sesClient.js"; import { getUniqueName } from "../../libs/utils/util-string.js"; const createCreateReceiptFilterCommand = ({ policy, ipOrRange, name }) => { return new CreateReceiptFilterCommand({ Filter: { IpFilter: { Cidr: ipOrRange, // string, either a single IP address (10.0.0.1) or an IP address range in CIDR notation (10.0.0.1/24)). Policy: policy, // enum ReceiptFilterPolicy, email traffic from the filtered addressesOptions. }, /* The name of the IP address filter. Only ASCII letters, numbers, underscores, or dashes. Must be less than 64 characters and start and end with a letter or number. */ Name: name, }, }); }; const FILTER_NAME = getUniqueName("ReceiptFilter"); const run = async () => { const createReceiptFilterCommand = createCreateReceiptFilterCommand({ policy: ReceiptFilterPolicy.Allow, ipOrRange: "10.0.0.1", name: FILTER_NAME, }); try { return await sesClient.send(createReceiptFilterCommand); } catch (err) { console.log("Failed to create filter.", err); return err; } };
-
Untuk detail API, lihat CreateReceiptFilterdi ReferensiAWS SDK for JavaScript API.
-
- Python
-
- SDK for Python (Boto3)
-
catatan Masih ada lagi GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di AWSCode Examples Repository
. 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_filter(self, filter_name, ip_address_or_range, allow): """ Creates a filter that allows or blocks incoming mail from an IP address or range. :param filter_name: The name to give the filter. :param ip_address_or_range: The IP address or range to block or allow. :param allow: When True, incoming mail is allowed from the specified IP address or range; otherwise, it is blocked. """ try: policy = 'Allow' if allow else 'Block' self.ses_client.create_receipt_filter( Filter={ 'Name': filter_name, 'IpFilter': { 'Cidr': ip_address_or_range, 'Policy': policy}}) logger.info( "Created receipt filter %s to %s IP of %s.", filter_name, policy, ip_address_or_range) except ClientError: logger.exception("Couldn't create receipt filter %s.", filter_name) raise
-
Untuk detail API, lihat CreateReceiptFilterdalam Referensi APIAWS SDK for Python (Boto3).
-
Untuk daftar lengkap panduan pengembangAWS SDK dan contoh kode, lihatMenggunakan Amazon SES denganAWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang versi SDK sebelumnya.