Função Enviar Emailg

download Função Enviar Emailg

of 4

description

gasdgsdggasgsd

Transcript of Função Enviar Emailg

FUNCTION z_enviar_email.*"----------------------------------------------------------------------*"*"Interface local:*" IMPORTING*" REFERENCE(ST_PARAM) TYPE ZSTPARAM_EMAIL*" REFERENCE(IT_EMAIL) TYPE SOMLRECI1_T*" REFERENCE(IT_BODY) TYPE CCRCTT_TEXT_TAB*" REFERENCE(IT_FILENAME) TYPE ZSTCFILENAMES OPTIONAL*" REFERENCE(IT_FILE) TYPE ZSTCFILES OPTIONAL*" REFERENCE(PE_SUBMIT) TYPE CHAR1 OPTIONAL*" TABLES*" PACKING_LIST STRUCTURE SOPCKLSTI1 OPTIONAL*" CONTENTS_HEX STRUCTURE SOLIX OPTIONAL*" EXCEPTIONS*" ERRO_AO_ENVIAR_EMAIL*"----------------------------------------------------------------------* Global data declarations DATA: it_body_locl TYPE ccrctt_text_tab, it_packing_list TYPE STANDARD TABLE OF sopcklsti1, it_email_int TYPE somlreci1_t, it_attach TYPE STANDARD TABLE OF solisti1. DATA: st_param_locl TYPE zstparam_email, st_email TYPE somlreci1, st_body TYPE solisti1, st_doc_data TYPE sodocchgi1, st_packing_list TYPE sopcklsti1, st_attach TYPE solisti1, st_filename TYPE zstefilenames, st_file TYPE zstefiles. DATA: l_nlines TYPE i, l_nlines2 TYPE i. "ONDA 3 - 07/02/2013 st_param_locl = st_param.* Verificar se est em um ambiente diferente de produo IF sy-sysid NE 'ECP'.*-- Incluir texto indicando que teste no ttulo e no corpo CONCATENATE 'E-MAIL DE TESTE'(001) st_param_locl-titulo INTO st_param_locl-titulo SEPARATED BY '-'. IF st_param-tpcorp = 'HTM'. CONCATENATE ''* 'border-color:#F0FFFF;' INTO st_body-line SEPARATED BY ' '. APPEND st_body TO it_body_locl. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = '--------------------------------------------------------------------------'(004). APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = 'ATENO'(002). APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = 'E-mail proveniente do ambiente de teste. Favor desconsiderar seu contedo.'(003). APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = '--------------------------------------------------------------------------'(004). APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. st_body-line = ''. APPEND st_body TO it_body_locl. ELSE. CLEAR st_body. INSERT st_body INTO it_body_locl INDEX 1. st_body-line = text-004. "Separador - INSERT st_body INTO it_body_locl INDEX 2. st_body-line = text-002. "Ateno INSERT st_body INTO it_body_locl INDEX 3. st_body-line = text-003. " E-mail proveniente do ambiente de teste. " Favor desconsiderar seu contedo. INSERT st_body INTO it_body_locl INDEX 4. st_body-line = text-004. "Separador - INSERT st_body INTO it_body_locl INDEX 5. ENDIF. ENDIF. APPEND LINES OF it_body TO it_body_locl. it_email_int[] = it_email[].* Determinar tamanho do documento DESCRIBE TABLE it_body_locl LINES l_nlines.* Incio de Alterao - ONDA 3 - 01/04/2013* READ TABLE it_body_locl INDEX 1 INTO st_body.* st_doc_data-doc_size = ( l_nlines - 1 ) * 255 + STRLEN( st_body ). st_doc_data-doc_size = ( l_nlines - 1 ) * 255 + 255.* Fim de Alterao - ONDA 3 - 01/04/2013* Atribuir demais campos do documento st_doc_data-obj_langu = sy-langu. st_doc_data-obj_name = 'E-MAIL'. st_doc_data-obj_descr = st_param_locl-titulo. st_doc_data-sensitivty = ' '.* Montar a Lista de Pacotes CLEAR st_packing_list. st_packing_list-head_start = 1. st_packing_list-head_num = 0. st_packing_list-body_start = 1. st_packing_list-body_num = l_nlines. st_packing_list-doc_type = st_param_locl-tpcorp. APPEND st_packing_list TO it_packing_list. LOOP AT it_file INTO st_file. AT NEW numarq.*---- Buscar nome do arquivo READ TABLE it_filename WITH KEY numarq = st_file-numarq INTO st_filename. CLEAR l_nlines2. "ONDA 3 - 07/02/2013 ENDAT. st_attach = st_file-line. APPEND st_attach TO it_attach. ADD 1 TO l_nlines2. "ONDA 3 - 07/02/2013 AT END OF numarq. DESCRIBE TABLE it_attach LINES l_nlines. CLEAR st_packing_list.* Incio de Alterao - ONDA 3 - 07/02/2013* st_packing_list-doc_size = ( l_nlines - 1 ) * 255 +* STRLEN( st_attach ). st_packing_list-doc_size = ( l_nlines2 - 1 ) * 255 + STRLEN( st_attach ).* Fim de Alterao - ONDA 3 - 07/02/2013 st_packing_list-transf_bin = 'X'. st_packing_list-head_start = 1. st_packing_list-head_num = 0.* Incio de Alterao - ONDA 3 - 07/02/2013* st_packing_list-body_start = 1.* st_packing_list-body_num = l_nlines. st_packing_list-body_start = l_nlines - l_nlines2 + 1. st_packing_list-body_num = l_nlines2.* Fim de Alterao - ONDA 3 - 07/02/2013 st_packing_list-body_num = l_nlines. st_packing_list-doc_type = st_param_locl-tpanex. st_packing_list-obj_name = 'FILE'. st_packing_list-obj_descr = st_filename-nomarq. APPEND st_packing_list TO it_packing_list. ENDAT. ENDLOOP. IF it_file[] IS INITIAL. LOOP AT packing_list. st_packing_list = packing_list. APPEND st_packing_list TO it_packing_list. ENDLOOP. ENDIF. CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = st_doc_data put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = it_packing_list contents_bin = it_attach contents_txt = it_body_locl contents_hex = contents_hex receivers = it_email_int EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 document_type_not_exist = 3 operation_no_authorization = 4 parameter_error = 5 x_error = 6 enqueue_error = 7 OTHERS = 8. IF sy-subrc EQ 0. IF pe_submit = 'X'. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' AND RETURN. ENDIF. ELSE. RAISE erro_ao_enviar_email. ENDIF.ENDFUNCTION.