Application Development and Automation 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: 
Read only

Problem in sending mails to multiple users Using the Class CL_BCS

Former Member
0 Likes
4,174

Hello Experts,

I am using the class CL_BCS for sending mails.

The problem is i am able to send mail to only one email-id.Now i need to send the mail to multiple email-id's.

I am getting an exception when i am trying to send the mail to the second email-id.

Please find below my code and suggest.

 
TRY.
*--Create persistent send request
    gc_send_request = cl_bcs=>create_persistent( ).

*--create and set document

*----Create document from internal table with text
    APPEND gw_text_mail TO tl_text.
    gc_document = cl_document_bcs=>create_document(
                    i_type    = gc_raw
                    i_text    = tl_text
                    i_length  = gc_len
                    i_subject = 'Testing upload of file' ).

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

*----Add recipient (e-mail address)
    LOOP AT r_email ASSIGNING <fs_mail>.
      ASSIGN COMPONENT 3 OF STRUCTURE <fs_mail> TO <fs_val>.
      gc_recipient = cl_cam_address_bcs=>create_internet_address(
                                        <fs_val> ).

*----Add recipient with its respective attributes to send request
      CALL METHOD gc_send_request->add_recipient
        EXPORTING
          i_recipient = gc_recipient
          i_express   = gc_express.

*----Send document
      CALL METHOD gc_send_request->send(
        EXPORTING
          i_with_error_screen = gc_err_screen
        RECEIVING
          result              = gw_sent_to_all ).
      IF gw_sent_to_all = gc_x.
        COMMIT WORK.
        MESSAGE s002(zfi_e012).
      ENDIF.

    ENDLOOP.

  CATCH cx_bcs INTO gc_bcs_exception.
    IF NOT gc_bcs_exception IS INITIAL.
      EXIT.
    ENDIF.
ENDTRY.

Regards,

Arun

Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 2:12 PM

1 ACCEPTED SOLUTION
Read only

Sm1tje
Active Contributor
0 Likes
1,860

Two suggestions:

1. what does the exception say? You are catching the error, but retrieve the actual message of this exception to find out what the exact problem is.

2. In stead of doing the send within the loop, do this outside of the loop. Add recipients within the loop and next do the send request. You are creating ONE document and are sending this in the first SEND, but next you want to send it again. Think this should then be a new document.

Hello Experts,

I am using the class CL_BCS for sending mails.

The problem is i am able to send mail to only one email-id.Now i need to send the mail to multiple email-id's.

I am getting an exception when i am trying to send the mail to the second email-id.

Please find below my code and suggest.

 
TRY.
*--Create persistent send request
    gc_send_request = cl_bcs=>create_persistent( ).

*--create and set document

*----Create document from internal table with text
    APPEND gw_text_mail TO tl_text.
    gc_document = cl_document_bcs=>create_document(
                    i_type    = gc_raw
                    i_text    = tl_text
                    i_length  = gc_len
                    i_subject = 'Testing upload of file' ).

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

*----Add recipient (e-mail address)
    LOOP AT r_email ASSIGNING <fs_mail>.
      ASSIGN COMPONENT 3 OF STRUCTURE <fs_mail> TO <fs_val>.
      gc_recipient = cl_cam_address_bcs=>create_internet_address(
                                        <fs_val> ).

*----Add recipient with its respective attributes to send request
      CALL METHOD gc_send_request->add_recipient
        EXPORTING
          i_recipient = gc_recipient
          i_express   = gc_express.

*----Send document
      CALL METHOD gc_send_request->send(
        EXPORTING
          i_with_error_screen = gc_err_screen
        RECEIVING
          result              = gw_sent_to_all ).
      IF gw_sent_to_all = gc_x.
        COMMIT WORK.
        MESSAGE s002(zfi_e012).
      ENDIF.

    ENDLOOP.

  CATCH cx_bcs INTO gc_bcs_exception.
    IF NOT gc_bcs_exception IS INITIAL.
      EXIT.
    ENDIF.
ENDTRY.

Regards,

Arun

Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 2:12 PM

3 REPLIES 3
Read only

Sm1tje
Active Contributor
0 Likes
1,861

Two suggestions:

1. what does the exception say? You are catching the error, but retrieve the actual message of this exception to find out what the exact problem is.

2. In stead of doing the send within the loop, do this outside of the loop. Add recipients within the loop and next do the send request. You are creating ONE document and are sending this in the first SEND, but next you want to send it again. Think this should then be a new document.

Read only

Former Member
0 Likes
1,860

Thanks a lot Micky.

Problem resolved.

Arun

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,860

Hello Arun

Using the coding shown below I have no problems to send e-mails to multiple receivers (1st = main, ELSE = Cc):


...
*     --------- set sender -------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.

      lo_sender = cl_sapuser_bcs=>create( sy-uname ).
      CALL METHOD lo_send_request->set_sender
        EXPORTING
          i_sender = lo_sender.

*     --------- add recipient (e-mail address) -----------------------
*   create recipients - please replace e-mail address !!!



      CALL FUNCTION 'Z_IDOC_MAINT_GET_MAIL_RCVR'
        IMPORTING
          et_receiver = lt_receiver.
      LOOP AT lt_receiver INTO ld_email.
*       1st receiver = main receiver, ELSE = Cc
        IF ( syst-tabix = 1 ).
          lx_copy = abap_false.
        ELSE.
          lx_copy = abap_true.
        ENDIF.

        lo_recipient = cl_cam_address_bcs=>create_internet_address(
                                          ld_email ).

*        TRY.
        CALL METHOD lo_send_request->add_recipient
          EXPORTING
            i_recipient = lo_recipient
            i_express   = 'X'
            i_copy      = lx_copy.
      ENDLOOP.
...

Regards

Uwe