Program To Send An Email In SAP ABAP With Example.

Send email Abap program

ABAP Program To Send An Email In SAP ABAP With Example.

Hello Guys my name is yogesh prajapati and today I’m going to tell You how you can send an email in abap. below in a sample program that you can use is your own.

First I’m going to tell you some steps that is important to write a program to send an email through ABAP Program.

DATA : i_poemail TYPE TABLE OF zyemail,
       w_poemail TYPE zyemail.
 
DATA : t_objbin  TYPE TABLE OF solisti1,   " Attachment data
       t_objtxt  TYPE TABLE OF solisti1,   " Message body
       t_objpack TYPE TABLE OF sopcklsti1, " Packing list
       t_reclist TYPE TABLE OF somlreci1,  " Receipient list
       t_objhead TYPE TABLE OF solisti1.   " Header
 
DATA : wa_docdata TYPE sodocchgi1,          " Document data
       wa_objtxt  TYPE solisti1,            " Message body
       wa_objbin  TYPE solisti1,            " Attachment data
       wa_objpack TYPE sopcklsti1,          " Packing list
       wa_objhead TYPE solisti1,          " Packing list
       wa_reclist TYPE somlreci1.           " Receipient list
 
DATA : v_name1     TYPE lfa1-name1,
       v_rlwrt(17) TYPE c,
       v_lines     TYPE i.
DATA : lv_bukrs TYPE bukrs.
DATA : lv_ebeln TYPE ebeln.
DATA : lv_werks TYPE werks_d.
 
IMPORT lv_ebeln TO lv_ebeln FROM MEMORY ID 'ZPOEMAIL_EBELN'.
IMPORT lv_bukrs TO lv_bukrs FROM MEMORY ID 'ZPOEMAIL_BUKRS'.
IMPORT lv_werks TO lv_werks FROM MEMORY ID 'ZPOEMAIL_WERKS'.
IF lv_bukrs IS NOT INITIAL AND lv_werks IS NOT INITIAL.
 
  SELECT *
  FROM zyemail  " Here Is My Email Id And few More Details
  INTO TABLE i_poemail
  WHERE bukrs  = lv_bukrs AND
        werks  = lv_werks AND
        sap_id = sy-uname.
ENDIF.
 
CONDENSE v_rlwrt.
 
REFRESH: t_objpack,
         t_objhead,
         t_objbin,
         t_objtxt,
         t_reclist,
         t_objbin,
         t_objhead.
 
CONCATENATE 'Released Purchase Order' ' ' INTO wa_docdata-obj_name
SEPARATED BY space.
 
APPEND wa_objbin TO t_objbin.
 
wa_docdata-obj_descr = 'Released Purchase Order'.
 
wa_objtxt-line = 'Hi, <br><br>'.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_objtxt.
 
CONCATENATE 'The Purchase Order <b> 'lv_ebeln' </b> has been released.' '<br><br>'
INTO wa_objtxt-line SEPARATED BY space.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_objtxt.
 
wa_objtxt-line = '<b>Details of the Purchase Order </b> <br>'.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_objtxt.
 
CONCATENATE 'PO Number: ' '<b>'lv_ebeln'</b>' '<br>'INTO wa_objtxt-line SEPARATED BY space.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_objtxt.
DATA lv_dats TYPE dats.
lv_dats = sy-datum.
CONCATENATE 'PO Released Date:' '<b>'lv_dats'</b>''<br><br><br><br>'INTO wa_objtxt-line SEPARATED BY space.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_objtxt.
 
wa_objtxt-line = '<i>This is system generated Mail, Do Not Reply!</i>'.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_objtxt.
 
IF t_reclist[] IS INITIAL.
  LOOP AT i_poemail INTO w_poemail.
    wa_reclist-receiver = w_poemail-email.
    wa_reclist-rec_type = 'U'.
    APPEND wa_reclist TO t_reclist.
    CLEAR  wa_reclist.
  ENDLOOP.
ENDIF.
 
DELETE t_reclist WHERE receiver IS INITIAL.
 
* Document data
DESCRIBE TABLE t_objtxt      LINES v_lines.
READ     TABLE t_objtxt      INTO wa_objtxt INDEX v_lines.
wa_docdata-doc_size =
    ( v_lines - 1 ) * 255 + strlen( wa_objtxt ).
 
* Packing data
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num   = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num   = v_lines.
*   we will pass the HTML, since we have created the message
*   body in the HTML
wa_objpack-doc_type   = 'HTML'.
APPEND wa_objpack TO t_objpack.
 
* Send Message to external Internet ID
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = wa_docdata "Pass Single line Data
    put_in_outbox              = 'X'
    commit_work                = 'X'     "used from rel.6.10
  TABLES
    packing_list               = t_objpack
    object_header              = t_objhead
    contents_txt               = t_objtxt
    receivers                  = t_reclist
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    document_type_not_exist    = 3
    operation_no_authorization = 4
    parameter_error            = 5
    x_error                    = 6
    enqueue_error              = 7
    OTHERS                     = 8.
 

Download ABAP Mail Code In Pdf

Top 10 Best Programming Languages To Learn In 2019.


2 thoughts on “Program To Send An Email In SAP ABAP With Example.”

  • Rakshit

    September 20, 2019 at 3:47 pm

    Thanks a Lot!! Code Downloaded.

    Reply
  • سکس

    September 21, 2019 at 5:15 pm

    tanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*