Ela é uma classe simples de utilizar, até mesmo para aqueles que ainda não estão acostumados com OO (ainda existe???).
Bom, vamos ao exemplo:
*&---------------------------------------------------------------------**& Report ZSEND_EMAIL*&*&---------------------------------------------------------------------**& ABAP Sample Code*& Send email with CL_BCS*&*& Maurício Lauffer - Brazil - 04.15.2014*& http://www.linkedin.com/in/mauriciolauffer*&*& This sample explains how to send an email using class: CL_BCS*&*&---------------------------------------------------------------------*REPORT zsend_email.CONSTANTS:gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS', " Email subjectgc_email_to TYPE adr6-smtp_addr VALUE 'frodo.baggins@lotr.com', " Valid emailgc_text TYPE soli VALUE 'Hello world! My first ABAP email!', " Text used into the email bodygc_type_raw TYPE so_obj_tp VALUE 'RAW'. " Email typeDATA:gt_text TYPE soli_tab, " Table which contains email body textgv_sent_to_all TYPE os_boolean, " Receive the information if email was sentgv_error_message TYPE string, " Used to get the error messagego_send_request TYPE REF TO cl_bcs, " Email objectgo_recipient TYPE REF TO if_recipient_bcs, " Who will receive the emailgo_sender TYPE REF TO cl_sapuser_bcs, " Who is sending the emailgo_document TYPE REF TO cl_document_bcs, " Email bodygx_bcs_exception TYPE REF TO cx_bcs.TRY."Create send requestgo_send_request = cl_bcs=>create_persistent( )."Email FROM...go_sender = cl_sapuser_bcs=>create( sy-uname )."Add sender to send requestgo_send_request->set_sender( i_sender = go_sender )."Email TO...go_recipient = cl_cam_address_bcs=>create_internet_address( gc_email_to )."Add recipient to send requestgo_send_request->add_recipient(EXPORTINGi_recipient = go_recipienti_express = abap_true)."Email BODYAPPEND gc_text TO gt_text.go_document = cl_document_bcs=>create_document(i_type = gc_type_rawi_text = gt_texti_length = '12'i_subject = gc_subject )."Add document to send requestgo_send_request->set_document( go_document )."Send email and get the resultgv_sent_to_all = go_send_request->send( i_with_error_screen = abap_true ).IF gv_sent_to_all = abap_true.WRITE 'Email sent!'.ENDIF."Commit to send emailCOMMIT WORK."Exception handlingCATCH cx_bcs INTO gx_bcs_exception.gv_error_message = gx_bcs_exception->get_text( ).WRITE gv_error_message.ENDTRY.
Agora é copiar/colar e começar a brincar.
Barbadinha!
Link do código no GitHub:
https://github.com/mauriciolauffer/ABAP/blob/master/Email/send_email.abap
Nenhum comentário:
Postar um comentário