Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CL_CBS class - Set e-mail address

Former Member
0 Kudos

Hi,

I try to send a mail with CL_CBS class.

I don't need to use the user mail but i have to set an external fixed e-mail address.

Is it possible to do these with CL_CBS class ? and if is it possible how can I do?

Thanks,

Michele Garofalo e Daniele Iadarola

2 REPLIES 2

former_member194669
Active Contributor
0 Kudos

Are you looking for this ?


          data: send_request       type ref to cl_bcs.
          move 'abc.abc.com' to it_recipient-smtp_addr.
          recipient = cl_cam_address_bcs=>create_internet_address(
  it_recipient-smtp_addr ).
          call method send_request->add_recipient
            exporting
              i_recipient  = recipient
              i_express    = ' '
              i_copy       = ' '
              i_blind_copy = ' '
              i_no_forward = ' '.

Former Member
0 Kudos

try this :

CLASS ca_sapuser_bcs     DEFINITION LOAD.
CLASS cl_cam_address_bcs DEFINITION LOAD.

DATA: send_request       TYPE REF TO cl_bcs.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: exception_info     TYPE REF TO if_os_exception_info,
      bcs_exception      type ref to cx_bcs.
data: num_rows           type i.
DATA: textlength         type SO_OBJ_LEN.
DATA: l_mailtext         type BCSY_TEXT.
data: l_line(255)        type c value 'prima riga'.
data: sender_name        like sy-uname . "value 'sender name'.
data: mail_address       type string  value 'fixed_mail_address'.
data: MESSAGES           type REF TO CL_BSP_MESSAGES.
data: mail_title         type SO_OBJ_DES value 'Doc_title'.
* set direct update
*try.
*  CALL METHOD cl_os_system=>init_and_set_modes
*          EXPORTING i_update_mode     = oscon_dmode_direct
*                    i_external_commit = oscon_true.
*
*  catch cx_os.
*    if messages is not initial.
*      messages->add_message( condition = 'mail'
*       message = 'Fehler beim Setzen des direkten Update aufgetreten' )
*.
*    endif.
*    exit.
*  endtry.

try.
* Create persistent send request
  send_request = cl_bcs=>create_persistent( ).

* Create document
  append l_line to l_mailtext.
  describe table l_mailtext lines num_rows.
  num_rows = num_rows * 255.
  move num_rows to textlength.
  document = cl_document_bcs=>create_document(
                      i_type    = 'RAW'
                      i_text    = l_mailtext
                      i_length  = textlength
                      i_subject = mail_title  ). "#EC *

* Add document to send request
  CALL METHOD send_request->set_document( document ).

* Get sender object
*TRY.
"deve essere il nome di un sap user"
move sy-uname to sender_name.
CALL METHOD CL_SAPUSER_BCS=>CREATE
  EXPORTING
    I_USER = sender_name
  RECEIVING
    RESULT = sender
    .
* CATCH CX_ADDRESS_BCS .
*ENDTRY.


*  sender = cl_sapuser_bcs=>create( sy-uname ).

* Add sender
  CALL METHOD send_request->set_sender
    EXPORTING i_sender = sender.

* Create recipient
  data: c_address TYPE ADR6-SMTP_ADDR.
  move mail_address to c_address.
  recipient = cl_cam_address_bcs=>create_internet_address(
                                            c_address ).

* Add recipient with its respective attributes to send request
  CALL METHOD send_request->add_recipient
    EXPORTING
        i_recipient  = recipient
        i_express    = ' '
        i_copy       = ' '
        i_blind_copy = ' '.

* Send document
  CALL METHOD send_request->send( ).

  COMMIT WORK.

  catch cx_bcs into bcs_exception.
    if messages is not initial.
      messages->add_message( condition = 'mail'
       message =
       'Fehler beim Versenden der Mail aufgetreten' )."#EC NOTEXT

    endif.

    exit.

  endtry.