Amazon SES API v2 examples using SDK for SAP ABAP - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Amazon SES API v2 examples using SDK for SAP ABAP

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for SAP ABAP with Amazon SES API v2.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use CreateContact.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.
  • For API details, see CreateContact in AWS SDK for SAP ABAP API reference.

The following code example shows how to use CreateContactList.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.

The following code example shows how to use CreateEmailIdentity.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.

The following code example shows how to use CreateEmailTemplate.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.

The following code example shows how to use DeleteContactList.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.

The following code example shows how to use DeleteEmailIdentity.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.

The following code example shows how to use DeleteEmailTemplate.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.

The following code example shows how to use ListContacts.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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.
  • For API details, see ListContacts in AWS SDK for SAP ABAP API reference.

The following code example shows how to use SendEmail.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

Sends a message.

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.

Sends a message using a template.

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.
  • For API details, see SendEmail in AWS SDK for SAP ABAP API reference.