使用适用于 SAP 的软件开发工具包的 Amazon SES API v2 示例 ABAP - Amazon 适用于 SAP 的 SDK ABA
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

使用适用于 SAP 的软件开发工具包的 Amazon SES API v2 示例 ABAP

以下代码示例向您展示了如何使用适用于 SAP ABAP 的软件开发工具包和 Amazon Amazon SES API v2 来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示了如何使用 CreateContact

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. lo_se2->createcontact( iv_contactlistname = iv_contact_list_name iv_emailaddress = iv_email_address ). MESSAGE 'Contact created successfully.' TYPE 'I'. CATCH /aws1/cx_se2alreadyexistsex. MESSAGE 'Contact already exists.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex. MESSAGE 'Bad request.' TYPE 'E'. CATCH /aws1/cx_se2notfoundexception. MESSAGE 'Contact list not found.' TYPE 'E'. ENDTRY.
  • 有关 API 的详细信息,请参阅适用CreateContact于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 CreateContactList

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. lo_se2->createcontactlist( iv_contactlistname = iv_contact_list_name ). MESSAGE 'Contact list created successfully.' TYPE 'I'. CATCH /aws1/cx_se2alreadyexistsex. MESSAGE 'Contact list already exists.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request - contact list limit may be reached.' TYPE 'I'. " Re-raise the exception so the caller can handle it RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_se2limitexceededex INTO DATA(lo_limit_exceeded). MESSAGE 'Limit exceeded - contact list limit reached.' TYPE 'I'. " Re-raise the exception so the caller can handle it RAISE EXCEPTION lo_limit_exceeded. ENDTRY.
  • 有关 API 的详细信息,请参阅适用CreateContactList于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 CreateEmailIdentity

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. lo_se2->createemailidentity( iv_emailidentity = iv_email_identity ). MESSAGE 'Email identity created successfully.' TYPE 'I'. CATCH /aws1/cx_se2alreadyexistsex. MESSAGE 'Email identity already exists.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request TYPE 'I' DISPLAY LIKE 'E'. CATCH /aws1/cx_se2limitexceededex INTO DATA(lo_limit_exceeded). MESSAGE lo_limit_exceeded TYPE 'I' DISPLAY LIKE 'E'. ENDTRY.
  • 有关 API 的详细信息,请参阅适用CreateEmailIdentity于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 CreateEmailTemplate

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. DATA(lo_template_content) = NEW /aws1/cl_se2emailtmplcontent( iv_subject = iv_subject iv_html = iv_html iv_text = iv_text ). lo_se2->createemailtemplate( iv_templatename = iv_template_name io_templatecontent = lo_template_content ). MESSAGE 'Email template created successfully.' TYPE 'I'. CATCH /aws1/cx_se2alreadyexistsex. MESSAGE 'Email template already exists.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex. MESSAGE 'Bad request.' TYPE 'E'. CATCH /aws1/cx_se2limitexceededex. MESSAGE 'Limit exceeded.' TYPE 'E'. ENDTRY.
  • 有关 API 的详细信息,请参阅适用CreateEmailTemplate于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 DeleteContactList

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. lo_se2->deletecontactlist( iv_contactlistname = iv_contact_list_name ). MESSAGE 'Contact list deleted successfully.' TYPE 'I'. CATCH /aws1/cx_se2notfoundexception. MESSAGE 'Contact list not found.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request.' TYPE 'I'. RAISE EXCEPTION lo_bad_request. ENDTRY.
  • 有关 API 的详细信息,请参阅适用DeleteContactList于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 DeleteEmailIdentity

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. lo_se2->deleteemailidentity( iv_emailidentity = iv_email_identity ). MESSAGE 'Email identity deleted successfully.' TYPE 'I'. CATCH /aws1/cx_se2notfoundexception. MESSAGE 'Email identity not found.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request.' TYPE 'I'. RAISE EXCEPTION lo_bad_request. ENDTRY.
  • 有关 API 的详细信息,请参阅适用DeleteEmailIdentity于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 DeleteEmailTemplate

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. lo_se2->deleteemailtemplate( iv_templatename = iv_template_name ). MESSAGE 'Email template deleted successfully.' TYPE 'I'. CATCH /aws1/cx_se2notfoundexception. MESSAGE 'Email template not found.' TYPE 'I'. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request.' TYPE 'I'. RAISE EXCEPTION lo_bad_request. ENDTRY.
  • 有关 API 的详细信息,请参阅适用DeleteEmailTemplate于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 ListContacts

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

TRY. oo_result = lo_se2->listcontacts( iv_contactlistname = iv_contact_list_name ). DATA(lv_count) = lines( oo_result->get_contacts( ) ). MESSAGE |Retrieved { lv_count } contacts from list.| TYPE 'I'. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request.' TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_se2notfoundexception INTO DATA(lo_not_found). MESSAGE 'Contact list not found.' TYPE 'I'. RAISE EXCEPTION lo_not_found. ENDTRY.
  • 有关 API 的详细信息,请参阅适用ListContacts于 S AP 的Amazon SDK ABAP API 参考

以下代码示例演示了如何使用 SendEmail

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

发送邮件。

TRY. " Create destination with recipient address DATA lt_to_addresses TYPE /aws1/cl_se2emailaddresslist_w=>tt_emailaddresslist. APPEND NEW /aws1/cl_se2emailaddresslist_w( iv_value = iv_to_email_address ) TO lt_to_addresses. DATA(lo_destination) = NEW /aws1/cl_se2destination( it_toaddresses = lt_to_addresses ). " Create message content DATA(lo_subject) = NEW /aws1/cl_se2content( iv_data = iv_subject ). DATA(lo_text_body) = NEW /aws1/cl_se2content( iv_data = iv_text_body ). DATA(lo_html_body) = NEW /aws1/cl_se2content( iv_data = iv_html_body ). DATA(lo_body) = NEW /aws1/cl_se2body( io_text = lo_text_body io_html = lo_html_body ). DATA(lo_message) = NEW /aws1/cl_se2message( io_subject = lo_subject io_body = lo_body ). DATA(lo_content) = NEW /aws1/cl_se2emailcontent( io_simple = lo_message ). " Send the email lo_se2->sendemail( iv_fromemailaddress = iv_from_email_address io_destination = lo_destination io_content = lo_content ). MESSAGE 'Email sent successfully.' TYPE 'I'. CATCH /aws1/cx_se2accountsuspendedex INTO DATA(lo_account_suspended). MESSAGE 'Account suspended.' TYPE 'I'. RAISE EXCEPTION lo_account_suspended. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request.' TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_se2messagerejected INTO DATA(lo_message_rejected). MESSAGE 'Message rejected - check email verification.' TYPE 'I'. RAISE EXCEPTION lo_message_rejected. ENDTRY.

使用模板发送消息。

TRY. " Create destination with recipient address DATA lt_to_addresses TYPE /aws1/cl_se2emailaddresslist_w=>tt_emailaddresslist. APPEND NEW /aws1/cl_se2emailaddresslist_w( iv_value = iv_to_email_address ) TO lt_to_addresses. DATA(lo_destination) = NEW /aws1/cl_se2destination( it_toaddresses = lt_to_addresses ). " Create template reference DATA(lo_template) = NEW /aws1/cl_se2template( iv_templatename = iv_template_name iv_templatedata = iv_template_data ). DATA(lo_content) = NEW /aws1/cl_se2emailcontent( io_template = lo_template ). " Create list management options DATA(lo_list_mgmt) = NEW /aws1/cl_se2listmanagementopts( iv_contactlistname = iv_contact_list_name ). " Send the email using template lo_se2->sendemail( iv_fromemailaddress = iv_from_email_address io_destination = lo_destination io_content = lo_content io_listmanagementoptions = lo_list_mgmt ). MESSAGE 'Email sent using template successfully.' TYPE 'I'. CATCH /aws1/cx_se2accountsuspendedex INTO DATA(lo_account_suspended). MESSAGE 'Account suspended.' TYPE 'I'. RAISE EXCEPTION lo_account_suspended. CATCH /aws1/cx_se2badrequestex INTO DATA(lo_bad_request). MESSAGE 'Bad request.' TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_se2messagerejected INTO DATA(lo_message_rejected). MESSAGE 'Message rejected - check email verification.' TYPE 'I'. RAISE EXCEPTION lo_message_rejected. ENDTRY.
  • 有关 API 的详细信息,请参阅适用SendEmail于 S AP 的Amazon SDK ABAP API 参考