Skip to Content
0
Former Member
Apr 27, 2005 at 05:28 AM

Sending mail from BSP

40 Views

Guys I am trying to send mail to my outlook using this program , the program is executing properly but I am not getting any emails. DO I need to configure SAP ?

Thanks

Manish

<i><b>CLASS ca_sapuser_bcs DEFINITION LOAD.

CLASS cl_cam_address_bcs DEFINITION LOAD.

DATA: l_rcl_send_request TYPE REF TO cl_bcs.

DATA: l_rcl_document TYPE REF TO cl_document_bcs.

DATA: l_rcl_sender TYPE REF TO cl_sapuser_bcs.

DATA: l_rif_recipient TYPE REF TO if_recipient_bcs.

DATA: l_rif_copy TYPE REF TO if_recipient_bcs.

DATA: l_rcl_bcs_exception TYPE REF TO cx_bcs.

DATA: l_cnt_num_rows TYPE i.

DATA: l_cnt_textlength TYPE so_obj_len.

DATA: l_tab_content TYPE soli_tab.

DATA: l_sav_sender TYPE sy-uname.

DATA: l_sav_address TYPE adr6-smtp_addr.

DATA: l_sav_subject TYPE so_obj_des.

TRY.

  • Create persistent send request

l_rcl_send_request = cl_bcs=>create_persistent( ).

  • data conversion is necessary even if Dataelement is the same

l_tab_content[] = i_tab_content[].

  • Create document

DESCRIBE TABLE i_tab_content LINES l_cnt_num_rows.

l_cnt_num_rows = l_cnt_num_rows * 255.

MOVE l_cnt_num_rows TO l_cnt_textlength.

  • Check for Subject

IF i_sav_subject IS INITIAL.

l_sav_subject = 'no subject'.

ELSE.

l_sav_subject = i_sav_subject.

ENDIF.

l_rcl_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = l_tab_content

i_length = l_cnt_textlength

i_subject = l_sav_subject ). "#EC *

  • Add document to send request

CALL METHOD l_rcl_send_request->set_document( l_rcl_document ).

  • Define Sender - check for import-parameter

IF i_sav_sender IS NOT INITIAL.

l_sav_sender = i_sav_sender.

ELSE.

l_sav_sender = sy-uname.

ENDIF.

  • Get sender object

l_rcl_sender = cl_sapuser_bcs=>create( l_sav_sender ).

  • Add sender

CALL METHOD l_rcl_send_request->set_sender

EXPORTING

i_sender = l_rcl_sender.

  • data conversion is necessary even if Dataelement is the same

l_sav_address = i_sav_smtp_receiver.

  • Create recipient

l_rif_recipient = cl_cam_address_bcs=>create_internet_address(

l_sav_address ).

  • Add recipient with its respective attributes to send request

CALL METHOD l_rcl_send_request->add_recipient

EXPORTING

i_recipient = l_rif_recipient

i_express = ' '

i_copy = ' '

i_blind_copy = ' '.

  • Create Copy receiver

IF i_sav_smtp_copy IS NOT INITIAL.

  • data conversion is necessary even if Dataelement is the same

l_sav_address = i_sav_smtp_copy.

  • Create recipient

l_rif_copy = cl_cam_address_bcs=>create_internet_address(

l_sav_address ).

  • Add recipient with its respective attributes to send request

CALL METHOD l_rcl_send_request->add_recipient

EXPORTING

i_recipient = l_rif_copy

i_express = ' '

i_copy = 'X'

i_blind_copy = ' '.

ENDIF.

  • Send document

CALL METHOD l_rcl_send_request->send( ).

COMMIT WORK.

  • catch errors and raise bapi exception

CATCH cx_bcs INTO l_rcl_bcs_exception.

call method messages->add_message

exporting

condition = 'E'

message = 'Message Not Sent'.

ENDTRY.</b></i>