Basic email program in ABAP

 Report program

REPORT zab_sen_auto_mail.

DATAlt_mailsub  TYPE sodocchgi1,
      lt_mailrecp TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,
      lt_mailtxt  TYPE STANDARD TABLE OF soli WITH HEADER LINE.

lt_mailrecp-rec_type 'U'.
lt_mailrecp-receiver 'abcd@gmail.com'.
APPEND lt_mailrecp.
CLEARlt_mailrecp.

lt_mailsub-obj_name 'TEST'.
lt_mailsub-obj_langu sy-langu.
lt_mailsub-obj_descr 'Mail Subject'.


lt_mailtxt 'This is test mail'.
APPEND lt_mailtxt.
CLEARlt_mailtxt.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    document_data              lt_mailsub
*   DOCUMENT_TYPE              = 'RAW'
*   PUT_IN_OUTBOX              = ' '
*   COMMIT_WORK                = ' '
*   IP_ENCRYPT                 =
*   IP_SIGN                    =
* IMPORTING
*   SENT_TO_ALL                =
*   NEW_OBJECT_ID              =
  TABLES
*   OBJECT_HEADER              =
    object_content             lt_mailtxt
*   CONTENTS_HEX               =
*   OBJECT_PARA                =
*   OBJECT_PARB                =
    receivers                  lt_mailrecp
  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.

IF sy-subrc <> 0.
  MESSAGE 'Mail not sent' TYPE 'E'.
ELSE.
  COMMIT WORK.
  MESSAGE 'Mail sent sucessfully' TYPE 'S'.
ENDIF.

****************************************************

* Execute the program email will trigger in SOST T-code.

* Goto T-code SOST.

* Select the email and click on display document.



Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).