{"id":7626,"date":"2025-08-24T16:37:12","date_gmt":"2025-08-24T11:07:12","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=email-funtionality-in-sap-abap"},"modified":"2025-08-24T16:37:12","modified_gmt":"2025-08-24T11:07:12","slug":"email-funtionality-in-sap-abap","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=email-funtionality-in-sap-abap","title":{"rendered":"Email Funtionality in SAP ABAP"},"content":{"rendered":"<h5>Steps to Send Email with Attachment in ABAP (Background)<\/h5>\n<ol>\n<li>Create document content (subject, body).<\/li>\n<li>Create an attachment (text, CSV, PDF, etc.).<\/li>\n<li>Build the BCS object and send.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>REPORT z_send_email_attachment.<\/p>\n<p>DATA: lo_send_request TYPE REF TO cl_bcs,<br \/>\nlo_document TYPE REF TO cl_document_bcs,<br \/>\nlo_sender TYPE REF TO cl_sapuser_bcs,<br \/>\nlo_recipient TYPE REF TO if_recipient_bcs.<\/p>\n<p>DATA: lt_message TYPE bcsy_text, &#8221; Body of email<br \/>\nlt_attach TYPE soli_tab, &#8221; Attachment content<br \/>\nlv_subject TYPE so_obj_des.<\/p>\n<p>START-OF-SELECTION.<\/p>\n<p>&#8220;1. Create Send Request<br \/>\nlo_send_request = cl_bcs=&gt;create_persistent( ).<\/p>\n<p>&#8220;2. Set Document (Email Content)<br \/>\nAPPEND &#8216;Hello,&#8217; TO lt_message.<br \/>\nAPPEND &#8216;This is a test email from ABAP background job.&#8217; TO lt_message.<br \/>\nAPPEND &#8216;Regards,&#8217; TO lt_message.<br \/>\nAPPEND &#8216;SAP System&#8217; TO lt_message.<\/p>\n<p>lv_subject = &#8216;ABAP Email with Attachment&#8217;.<\/p>\n<p>lo_document = cl_document_bcs=&gt;create_document(<br \/>\ni_type = &#8216;RAW&#8217;<br \/>\ni_text = lt_message<br \/>\ni_subject = lv_subject ).<\/p>\n<p>&#8220;3. Create Attachment (simple TXT file here)<br \/>\nCLEAR lt_attach.<br \/>\nAPPEND &#8216;Material;Plant;MRP Type&#8217; TO lt_attach.<br \/>\nAPPEND &#8216;MAT001;1000;PD&#8217; TO lt_attach.<br \/>\nAPPEND &#8216;MAT002;1100;VB&#8217; TO lt_attach.<\/p>\n<p>lo_document-&gt;add_attachment(<br \/>\ni_attachment_type = &#8216;TXT&#8217; &#8221; TXT, XLS, PDF etc.<br \/>\ni_attachment_subject = &#8216;MARA_MARC_List&#8217;<br \/>\ni_att_content_text = lt_attach ).<\/p>\n<p>&#8220;4. Add Document to Send Request<br \/>\nlo_send_request-&gt;set_document( lo_document ).<\/p>\n<p>&#8220;5. Sender (SAP user)<br \/>\nlo_sender = cl_sapuser_bcs=&gt;create( sy-uname ).<br \/>\nlo_send_request-&gt;set_sender( lo_sender ).<\/p>\n<p>&#8220;6. Recipient (email address)<br \/>\nlo_recipient = cl_cam_address_bcs=&gt;create_internet_address(<br \/>\n&#8216;testuser@example.com&#8217; ).<br \/>\nlo_send_request-&gt;add_recipient(<br \/>\ni_recipient = lo_recipient<br \/>\ni_express = &#8216;X&#8217; ).<\/p>\n<p>&#8220;7. Send Email<br \/>\nlo_send_request-&gt;send( i_with_error_screen = &#8216;X&#8217; ).<\/p>\n<p>COMMIT WORK.<br \/>\nWRITE: &#8216;Email sent successfully&#8217;.<\/p>\n<p>&nbsp;<\/p>\n<h5>Key Points<\/h5>\n<ul>\n<li><code>cl_bcs<\/code> framework works in background and supports all formats.<\/li>\n<li>You can attach:\n<ul>\n<li>TXT\/CSV \u2192 use <code>i_att_content_text<\/code><\/li>\n<li>Binary (PDF, Excel, Word) \u2192 use <code>i_att_content_hex<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Run in background \u2192 email will still be sent (no popup).<\/li>\n<li>Use <code>COMMIT WORK<\/code> \u2192 ensures email is queued in SAPconnect.<\/li>\n<li>Check status in SOST transaction.<\/li>\n<\/ul>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[178,369,177],"class_list":["post-7626","question","type-question","status-publish","hentry","question-category-abap","question_tags-abap","question_tags-email","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7626"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7626"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7626"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}