{"id":13698418,"url":"https://github.com/vidyadharg/ABAP-HTML-eMail","last_synced_at":"2025-05-04T03:31:19.571Z","repository":{"id":173973830,"uuid":"442124249","full_name":"vidyadharg/ABAP-HTML-eMail","owner":"vidyadharg","description":"SAP ABAP send email using eMail Templates with or without CDS","archived":false,"fork":false,"pushed_at":"2024-12-14T06:50:02.000Z","size":42,"stargazers_count":11,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-14T07:26:46.977Z","etag":null,"topics":["abap-html-email","cl-smtg-email-api","email-templates","smtg-wb-start"],"latest_commit_sha":null,"homepage":"","language":"ABAP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vidyadharg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-12-27T10:17:03.000Z","updated_at":"2024-12-14T06:50:07.000Z","dependencies_parsed_at":"2024-04-08T02:53:38.263Z","dependency_job_id":"ea94d523-56c7-46c3-85b7-18f6eb4b3de1","html_url":"https://github.com/vidyadharg/ABAP-HTML-eMail","commit_stats":null,"previous_names":["vidyadharg/abap-html-email"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidyadharg%2FABAP-HTML-eMail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidyadharg%2FABAP-HTML-eMail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidyadharg%2FABAP-HTML-eMail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vidyadharg%2FABAP-HTML-eMail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vidyadharg","download_url":"https://codeload.github.com/vidyadharg/ABAP-HTML-eMail/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252283595,"owners_count":21723505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abap-html-email","cl-smtg-email-api","email-templates","smtg-wb-start"],"created_at":"2024-08-02T19:00:45.974Z","updated_at":"2025-05-04T03:31:19.181Z","avatar_url":"https://github.com/vidyadharg.png","language":"ABAP","readme":"# SAP ABAP send email using eMail Templates with or without CDS\n##  1.\tCreate E-Mail Template\n  ![image](https://user-images.githubusercontent.com/28149363/147467514-c82fdba0-99b3-40f8-b760-3dd5b9f33173.png)\n\n![image](https://user-images.githubusercontent.com/28149363/171146686-18c41e2f-1d1a-466d-be1a-0b2e818f911f.png)\n\n![image](https://user-images.githubusercontent.com/28149363/171146887-5a05bbf1-44ca-4f1c-8a2b-9daeb7f3043a.png)\n\n\n##  2.\tCreate class ZCL_EMAIL inheriting from CL_BCS_MESSAGE  \n\n    2.1.\tMETHODS SET_BODY_SO10 \" get Email body from so10 text.\n\n    2.2.\tMETHODS SET_PLACEHOLDER \" set dynamic variable to be replaced in email to body\n\n    2.3.\tMETHODS replace_placeholder \" replace placehoder for non cds email template\n    \n    2.4.\tMETHODS SET_PLACEHOLDER_ITAB \" replace Itab  placehoder for non cds email template\n\n    2.5.\tMETHODS SET_SUB_BODY_TEMPLATE \"read email body from email template\n\n      \"2.5.1.\tDont pass place holders when Email teplate created without CDS.\n\n      SELECT SINGLE cds_view FROM smtg_tmpl_hdr\n              INTO @DATA(lv_cds_view)\n              WHERE id      EQ @iv_template_id\n                AND version EQ 'A'. \"GC_VERSION_ACTIVE\n            IF sy-subrc EQ 0.\n              IF lv_cds_view IS NOT INITIAL.\n                DATA(lt_data_key) = gt_data_key.\n              ENDIF.\n\n      \"2.5.2.\tRead email template in HTML or Text.\n        TRY.\n            DATA(lo_email_api) = cl_smtg_email_api=\u003eget_instance( iv_template_id = iv_template_id ).\n\n            lo_email_api-\u003erender(\n              EXPORTING\n                iv_language  = iv_lang\n                it_data_key  = lt_data_key\n              IMPORTING\n                ev_subject   = DATA(lv_subject)\n                ev_body_html = DATA(lv_body_html)\n                ev_body_text = DATA(lv_body_text) ).\n\n          CATCH cx_smtg_email_common INTO DATA(ex). \" E-Mail API Exceptions\n        ENDTRY. \n\n      \"2.5.3.\tReplace placehoder for non-cds email template\n\n          IF iv_doctype EQ 'HTM'.\n            DATA(lv_mailbody) = lv_body_html.\n          ELSE.\n            lv_mailbody = lv_body_text.\n          ENDIF.\n\n          IF lv_cds_view IS INITIAL.\n            lv_mailbody = replace_placeholder( lv_mailbody ).\n            lv_subject = replace_placeholder( lv_subject ).\n          ENDIF.\n\n      \"2.5.4.\tset subject and body using supper class CL_BCS_MESSAGE \n\n         set_subject( lv_subject ).\n         \n         set_main_doc(\n                 EXPORTING\n                   iv_contents_txt = lv_mailbody      \" Main Documet, First Body Part\n                   iv_doctype      = iv_doctype ).     \" Document Category\n\n    ```\n\n##  3.\tDemo program  \n\n```\nREPORT zdemo_email.\n\"send email with HTML body using email template\n\nTRY.\n    DATA(email) = NEW zcl_email( ).\n    data lv_expiry_dt TYPE dats.\n\n  select CARRID, CONNID, FLDATE, PRICE\n    UP TO 10 ROWS FROM SFLIGHT INTO TABLE @data(lt_SFLIGHT).\n\n    lv_expiry_dt  = sy-datum + 10. \"add logic to get user id expiry date\n\n    DATA(lv_days) = lv_expiry_dt - sy-datum.\n\n    email-\u003eadd_recipient( iv_address = CONV #( 'recipient@emailid.com' ) ).\n\n    email-\u003eset_sender( iv_address = 'do@not.reply' iv_visible_name = 'Do not reply ' ).\n\n    \"set internal table as html email body \n    email-\u003eset_placeholder_itab(\n      EXPORTING\n        placeholder_name  = '\u0026SFLIGHT_TAB\u0026'\n        placeholder_itab = lt_SFLIGHT\n        table_Title =  'Flights Details').\n\n    email-\u003eset_placeholder(\n      EXPORTING\n        placeholder_name  = '\u0026USER_FIRST_NAME\u0026'\n        placeholder_value =  CONV #( 'User firstname' ) ).\n\n    email-\u003eset_placeholder(\n      EXPORTING\n        placeholder_name  = '\u0026USER_ID\u0026'\n        placeholder_value = CONV #( 'user_id' ) ).\n\n    email-\u003eset_placeholder(\n      EXPORTING\n        placeholder_name  =  '\u0026EXPIRY_DT\u0026'\n        placeholder_value =  |{ lv_expiry_dt DATE = ISO }| ).\n\n    email-\u003eset_placeholder(\n      EXPORTING\n        placeholder_name  =  '\u0026DAYS\u0026'\n        placeholder_value =  CONV #( lv_days ) ).\n\n    email-\u003eset_subject_body_template(\n      EXPORTING\n        template_id = 'ZET_DEMO' \"Email body from Email template\n        doctype      = 'HTM' ).\n\n    email-\u003eset_send_immediately( abap_false ).\n    email-\u003esend( ).\n\n  CATCH cx_bcs_send INTO DATA(ex).\n    MESSAGE ex-\u003eget_text( ) TYPE 'S'.\nENDTRY.\n```\n\n##  4.\tSOST email preview\n![image](https://user-images.githubusercontent.com/28149363/171146985-1208eb8c-8204-4c30-875a-bbf3b5309ae9.png)\n\n\n","funding_links":[],"categories":["Categories"],"sub_categories":["🗒️ eMail \u0026 Document Processing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvidyadharg%2FABAP-HTML-eMail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvidyadharg%2FABAP-HTML-eMail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvidyadharg%2FABAP-HTML-eMail/lists"}