Skip to end of metadata
Go to start of metadata

Author: Mauricio Lauffer
Submitted: 08/03/2012
Related Links:

Send email with new class CL_BCS is very simple!

Follow a example:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*& Report  ZEMAIL_CL_BCS                                       *
*& Mauricio Lauffer

  REPORT  zemail_cl_bcs.

    gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS',
    gc_raw     TYPE char03 VALUE 'RAW'.

    gv_mlrec         TYPE so_obj_nam,
    gv_sent_to_all   TYPE os_boolean,
    gv_email         TYPE adr6-smtp_addr,
    gv_subject       TYPE so_obj_des,
    gv_text          TYPE bcsy_text,
    gr_send_request  TYPE REF TO cl_bcs,
    gr_bcs_exception TYPE REF TO cx_bcs,
    gr_recipient     TYPE REF TO if_recipient_bcs,
    gr_sender        TYPE REF TO cl_sapuser_bcs,
    gr_document      TYPE REF TO cl_document_bcs.

      "Create send request
      gr_send_request = cl_bcs=>create_persistent( ).

      "Email FROM...
      gr_sender = cl_sapuser_bcs=>create( sy-uname ).
      "Add sender to send request
      CALL METHOD gr_send_request->set_sender
          i_sender = gr_sender.

      "Email TO...
      gv_email = ''.
      gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
      "Add recipient to send request
      CALL METHOD gr_send_request->add_recipient
          i_recipient = gr_recipient
          i_express   = 'X'.

      "Email BODY
      APPEND 'Hello world! My first ABAP email!' TO gv_text.
      gr_document = cl_document_bcs=>create_document(
                      i_type    = gc_raw
                      i_text    = gv_text
                      i_length  = '12'
                      i_subject = gc_subject ).
      "Add document to send request
      CALL METHOD gr_send_request->set_document( gr_document ).

      "Send email
      CALL METHOD gr_send_request->send(
          i_with_error_screen = 'X'
          result              = gv_sent_to_all ).
      IF gv_sent_to_all = 'X'.
        WRITE 'Email sent!'.

      "Commit to send email

      "Exception handling
    CATCH cx_bcs INTO gr_bcs_exception.
        'Error type:',


  1. Yes, it's very simple...... 

    Thanks for sharing........

  2. 1) how to add our own custom hardcoded sender mail id without creating with my username in above program.

    2) how to increase the subject length from 50 char to 100 char.

  3. Thanks man ....

    Easy to understand ,very helpfull...

    Thanks again ..

  4. does frodo know about this (smile)

    thank you