Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ****** zca_email_content DDIC defintion ************
- SENDER SYUNAME
- SUBJECT SO_OBJ_DES
- BODY_T BCSY_TEXT
- ATTACH_NAME SO_OBJ_DES
- ATTACH_TYPE CHAR3
- ****** PUBLIC CLASS SECTION ************
- class zcl_ca_tools definition
- public
- final
- create public .
- *"* public components of class ZCL_CA_TOOLS
- *"* do not include other source files here!!!
- public section.
- type-pools abap .
- methods send_email_attach
- importing
- !is_email_content type zca_email_content
- !it_recipients_smtp type isu_adr6_tab optional
- !it_recipients_sapid type uiys_iusr optional
- !it_attach type solix_tab optional
- !ir_attach_ref type ref to solix_tab optional
- returning
- value(rv_result) type abap_bool
- raising
- cx_address_bcs
- cx_send_req_bcs .
- ****** Method ************
- method send_email_attach.
- ********************************************************************************
- * sends mail either as BCS or SMTP-EMAIL depending on the parameter supplied
- ********************************************************************************
- *Data Declaration
- data: lo_sender type ref to if_sender_bcs value is initial,
- lo_send_request type ref to cl_bcs value is initial,
- lo_recipient type ref to if_recipient_bcs value is initial,
- lo_document type ref to cl_document_bcs value is initial,
- ls_recipient_smtp type adr6,
- lv_recipient_uid type uname.
- clear: ls_recipient_smtp, lv_recipient_uid.
- * Prepare Mail Object
- class cl_bcs definition load.
- try.
- lo_send_request = cl_bcs=>create_persistent( ).
- catch cx_send_req_bcs.
- endtry.
- * Message body and subject
- try.
- lo_document = cl_document_bcs=>create_document(
- i_type = 'RAW'
- i_text = is_email_content-body_t
- i_subject = is_email_content-subject ).
- if it_attach is supplied.
- lo_document->add_attachment(
- i_attachment_type = is_email_content-attach_type
- i_attachment_subject = is_email_content-attach_name
- i_att_content_hex = it_attach
- ).
- elseif ir_attach_ref is supplied.
- if ir_attach_ref is bound.
- lo_document->add_attachment(
- i_attachment_type = is_email_content-attach_type
- i_attachment_subject = is_email_content-attach_name
- i_att_content_hex = ir_attach_ref->*[]
- ).
- endif.
- endif.
- catch cx_document_bcs .
- endtry.
- * Pass the document to send request
- try.
- lo_send_request->set_document( lo_document ).
- catch cx_send_req_bcs.
- endtry.
- * Set Sender
- if is_email_content-sender is not initial.
- try.
- lo_sender = cl_sapuser_bcs=>create( is_email_content-sender ).
- catch cx_address_bcs.
- endtry.
- else.
- try.
- lo_sender = cl_sapuser_bcs=>create( sy-uname ).
- catch cx_address_bcs.
- endtry.
- endif.
- try.
- lo_send_request->set_sender(
- exporting
- i_sender = lo_sender ).
- catch cx_send_req_bcs.
- return.
- endtry.
- * Set recipients
- * if IT_RECIPIENTS_SMTP is supplied, we do not process IT_RECIPIENTS_SAPID
- if it_recipients_smtp is not initial.
- loop at it_recipients_smtp into ls_recipient_smtp.
- try.
- lo_recipient = cl_cam_address_bcs=>create_internet_address( ls_recipient_smtp-smtp_addr ).
- catch cx_address_bcs.
- endtry.
- try.
- lo_send_request->add_recipient(
- i_recipient = lo_recipient
- i_express = abap_true ).
- catch cx_send_req_bcs.
- endtry.
- endloop.
- else.
- if it_recipients_sapid is not initial.
- lv_recipient_uid = it_recipients_sapid-iusrid.
- lo_recipient = cl_sapuser_bcs=>create( lv_recipient_uid ).
- lo_send_request->add_recipient(
- i_recipient = lo_recipient
- i_express = abap_true ).
- endif.
- endif.
- * Send email
- try.
- lo_send_request->set_send_immediately( abap_true ).
- rv_result = lo_send_request->send( i_with_error_screen = abap_true ).
- catch cx_send_req_bcs.
- rv_result = ''.
- endtry.
- * dont forget to COMMIT WORK AND WAIT if the system does not do it for you
- endmethod.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement