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 with sending email using cl_bcs class

Former Member
0 Likes
5,474

Good morning,

I tried to send out an email to internet adress using cl_bsc class but I could not find it through SOST tcode.

Please help! Following is the source code:

report  z_test.

  DATA: send_request        TYPE REF TO cl_bcs.
  DATA: li_main_text        TYPE bcsy_text,
        lw_main_text        LIKE LINE OF li_main_text.

  DATA: document            TYPE REF TO cl_document_bcs.
  DATA: recipient           TYPE REF TO if_recipient_bcs.
  DATA: sender              TYPE REF TO if_sender_bcs.

  DATA: l_mtitle            LIKE sodocchgi1-obj_descr.
  DATA: sent_to_all         TYPE os_boolean.
  DATA: bcs_exception       TYPE REF TO cx_bcs.

  TRY.
*     -------- create persistent send request ------------------------
      send_request = cl_bcs=>create_persistent( ).
*     -------- create and set document---------------
*     Email title
      l_mtitle = 'Testing Email from Khaliachika'.

*     Fill the body of the mail
      REFRESH li_main_text.

      lw_main_text = 'Testing email'.
      APPEND lw_main_text TO li_main_text.
      CLEAR: lw_main_text.

      document = cl_document_bcs=>create_document(
        i_type    = 'RAW'
        i_text    = li_main_text
        i_subject = l_mtitle ).

*     Add document object to send request
      send_request->set_document( document ).
*     Sender infor
      sender = cl_cam_address_bcs=>create_internet_address(
                'email address here' ).	"Since SDN does not allow to put email address
      send_request->set_sender( sender ).

*     --------- add recipient (e-mail address) -----------------------
      recipient =
          cl_cam_address_bcs=>create_internet_address(
                'email address' ).

*     Add recipient object to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient = recipient
          i_express   = 'X'.

*     ---------- send document ---------------------------------------
      sent_to_all = send_request->send( i_with_error_screen = 'X' ).

*      IF sent_to_all IS INITIAL.
      IF sent_to_all IS INITIAL.
        MESSAGE i500(sbcoms) WITH 'email address'.
        EXIT.
      ENDIF.

      COMMIT WORK.
*   ------------ exception handling ----------------------------------
    CATCH cx_bcs INTO bcs_exception.
      MESSAGE i865(so) WITH bcs_exception->error_type.
  ENDTRY.

Thanks,

Khanh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,384

Hi,

Any idea please?

<< Removed >>

Everything was OK and send_to_all = 'X' but I could not see the email in SOST.

By the way, the lastest email I can see in SOST was 3 months ago.

Any suggestion?

Thanks,

Khanh

Edited by: khaliachika on Apr 28, 2010 8:01 PM

Edited by: Rob Burbank on Apr 28, 2010 3:04 PM

5 REPLIES 5
Read only

Former Member
0 Likes
2,385

Hi,

Any idea please?

<< Removed >>

Everything was OK and send_to_all = 'X' but I could not see the email in SOST.

By the way, the lastest email I can see in SOST was 3 months ago.

Any suggestion?

Thanks,

Khanh

Edited by: khaliachika on Apr 28, 2010 8:01 PM

Edited by: Rob Burbank on Apr 28, 2010 3:04 PM

Read only

0 Likes
2,384

Is the Recipient Email address maintained in SCOT ?. It needs to be maintained in SCOT.

Read only

0 Likes
2,384

>

> By the way, the lastest email I can see in SOST was 3 months ago.

That may be the problem. I ran your program and it sent and received an e-mail.

Rob

Read only

phanir_mullapudi
Active Participant
0 Likes
2,384

This message was moderated.

Read only

0 Likes
2,384

Hi Phani,

The issue was because of SOST configuration, it was default uncheck the option 'Select waiting send requests in selected time period only' in Options tab.

I rewarded you 2 points already.

I tried Rob's suggestion and found the target.

Thanks for your time,

Khanh

Edited by: khaliachika on Apr 29, 2010 1:12 AM