文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
SendBulkEmail搭配使用 AWS SDK
以下代码示例演示如何使用 SendBulkEmail。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 class SESv2Wrapper: """Encapsulates Amazon SESv2 email sending actions.""" def __init__(self, sesv2_client: Any) -> None: """ Initializes the SESv2Wrapper with an SESv2 client. :param sesv2_client: A Boto3 SESv2 client. """ self.sesv2_client = sesv2_client @classmethod def from_client(cls) -> "SESv2Wrapper": """ Creates an SESv2Wrapper instance with a default Boto3 SESv2 client. :return: A new SESv2Wrapper instance. """ sesv2_client = boto3.client("sesv2") return cls(sesv2_client) def send_bulk_email( self, from_address: str, template_name: str, default_template_data: str, bulk_entries: List[Dict[str, Any]], attachments: Optional[List[Dict[str, Any]]] = None, ) -> List[Dict[str, Any]]: """ Sends a templated email to multiple recipients in a single API call. All recipients receive the same attachment(s) defined in the default content, while template data can be personalized per recipient. :param from_address: The verified sender email address. :param template_name: The name of an existing email template. :param default_template_data: Default JSON template data string. :param bulk_entries: A list of BulkEmailEntry dicts, each containing 'Destination' and optionally 'ReplacementEmailContent'. :param attachments: An optional list of attachment dicts for all recipients. :return: A list of BulkEmailEntryResult dicts with status and MessageId. :raises ClientError: If the message is rejected (MessageRejected). """ try: template_content: Dict[str, Any] = { "TemplateName": template_name, "TemplateData": default_template_data, } if attachments: template_content["Attachments"] = attachments response = self.sesv2_client.send_bulk_email( FromEmailAddress=from_address, DefaultContent={"Template": template_content}, BulkEmailEntries=bulk_entries, ) results = response.get("BulkEmailEntryResults", []) logger.info( "Sent bulk email from %s to %d recipients.", from_address, len(bulk_entries), ) return results except ClientError as err: if err.response["Error"]["Code"] == "MessageRejected": logger.error( "Bulk message was rejected. Check that the template " "exists, attachment file types are supported, and " "total message size is within limits. Details: %s", err.response["Error"]["Message"], ) else: logger.error( "Couldn't send bulk email. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise-
有关 API 的详细信息,请参阅适用SendBulkEmail于 Python 的AWS SDK (Boto3) API 参考。
-
- SAP ABAP
-
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 TRY. " Build the default template content used for all bulk recipients DATA(lo_template) = NEW /aws1/cl_se2template( iv_templatename = iv_template_name iv_templatedata = iv_template_data ). DATA(lo_default_content) = NEW /aws1/cl_se2bulkemailcontent( io_template = lo_template ). DATA(lo_result) = lo_se2->sendbulkemail( iv_fromemailaddress = iv_from_address io_defaultcontent = lo_default_content it_bulkemailentries = it_bulk_entries ). ot_results = lo_result->get_bulkemailentryresults( ). MESSAGE |Bulk email sent to { lines( it_bulk_entries ) } recipient(s).| TYPE 'I'. CATCH /aws1/cx_se2messagerejected INTO DATA(lo_rejected). MESSAGE lo_rejected TYPE 'I' DISPLAY LIKE 'E'. RAISE EXCEPTION lo_rejected. CATCH /aws1/cx_se2mailfrmdomnotver00 INTO DATA(lo_not_verified). MESSAGE lo_not_verified TYPE 'I' DISPLAY LIKE 'E'. RAISE EXCEPTION lo_not_verified. CATCH /aws1/cx_se2notfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found TYPE 'I' DISPLAY LIKE 'E'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request TYPE 'I' DISPLAY LIKE 'E'. RAISE EXCEPTION lo_bad_request. ENDTRY.-
有关 API 的详细信息,请参阅适用SendBulkEmail于 S AP 的AWS SDK ABAP API 参考。
-
ListContacts
SendEmail