PDA

Ver la Versión Completa : Enviar Mail con un archivo word o excel adjunto


Mike
14/03/06, 14:40:27
Buenos Dias, Hola a todos en el foro tengo una pregunta espero me puedan ayudar.

Quiero enviar un mail a traves de un programa pero dicho mail debe tener un archivo adjunto de extensión .DOC o .XLS. Si alguien puede ayudarme..

Gracias..

Saludos

erp
14/03/06, 17:29:45
Hola Mike,

Te pongo una función que encontré para para enviar mail con anexos

LZGE003TOP
---------------

function-pool zge003. "MESSAGE-ID ..

*----------------------------------------------------------------------*
* DEFINICIÓN DE TABLAS *
*----------------------------------------------------------------------*
tables: tsp01. " SPOOL: Demandas

*----------------------------------------------------------------------*
* DEFINICIÓN DE ESTRUCTURAS *
*----------------------------------------------------------------------*
data: e_datos_doc like sodocchgi1.

*----------------------------------------------------------------------*
* DEFINICIÓN DE TABLAS INTERNAS *
*----------------------------------------------------------------------*
data: i_objpack like sopcklsti1 occurs 0 with header line,
i_cabecera like solisti1 occurs 0 with header line,
i_destinatario like somlreci1 occurs 0 with header line,
i_pdf like tline occurs 0 with header line,
i_bin like solisti1 occurs 0 with header line,
i_cont_bin like solisti1 occurs 0 with header line,
i_texto like solisti1 occurs 0 with header line.

*----------------------------------------------------------------------*
* DEFINICIÓN DE VARIABLES *
*----------------------------------------------------------------------*
data: v_lineas like sy-tabix,
v_lineas_tot like sy-tabix,
v_num_bytes type i,
v_len like sy-index,
v_long like sy-index,
v_queda like sy-index,
v_offset like sy-index,
v_indice like sy-index.

Código
--------


function z_ge_mailspool.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" REFERENCE(V_DESTINATARIO) LIKE SOMLRECI1-RECEIVER
*" REFERENCE(V_TIPO) LIKE SOMLRECI1-REC_TYPE DEFAULT 'B'
*" REFERENCE(V_TITULO) LIKE SODOCCHGI1-OBJ_DESCR
*" REFERENCE(V_DESCR_TXT) LIKE SOPCKLSTI1-OBJ_DESCR OPTIONAL
*" TABLES
*" I_TEXTO STRUCTURE SOLISTI1
*" I_SPOOLS STRUCTURE ZEGESPOOL
*" I_ANEXO STRUCTURE SOLISTI1
*" EXCEPTIONS
*" SPOOL_NO_EXISTE
*" SPOOL_NO_ES_UN_FORMULARIO
*" DOCUMENTO_NO_ENVIADO
*" SIN_AUTORIZACION
*" ERROR_INTERNO
*"---------------------------------------------------------------------- * Se indica la información necesaria para la impresión del texto
describe table i_texto lines v_lineas.
refresh i_objpack.
clear i_objpack.
v_indice = 1.
i_objpack-transf_bin = ' '.
i_objpack-head_start = v_indice.
i_objpack-body_start = 1.
i_objpack-body_num = v_lineas.
i_objpack-doc_type = 'RAW'.
append i_objpack.

* A la tabla de texto se le añadirá el contenido del anexo
append lines of i_anexo to i_texto.
v_indice = v_indice + 1.
i_objpack-transf_bin = ' '.
i_objpack-head_start = v_indice.
i_objpack-body_start = v_lineas + 1.
i_objpack-obj_descr = v_descr_txt.
describe table i_anexo lines v_lineas.
i_objpack-body_num = v_lineas.
i_objpack-doc_type = 'RAW'.
append i_objpack.

* Y las informaciones necesarias para adjuntar los spools indicados
refresh i_cont_bin.
v_indice = v_lineas.
loop at i_spools.

perform comprobar_orden_spool using i_spools-rqident.
perform llenar_tabla_bin using i_spools-rqident.

v_indice = v_indice + 1.
clear i_objpack.
i_objpack-transf_bin = 'X'.
describe table i_cont_bin lines v_lineas_tot.
i_objpack-head_start = v_lineas_tot + 1.
i_objpack-body_start = v_lineas_tot + 1.
describe table i_bin lines v_lineas.
i_objpack-body_num = v_lineas.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_descr = i_spools-nombre.
i_objpack-doc_size = v_num_bytes.
append i_objpack.
append lines of i_bin to i_cont_bin.

endloop.

* Información acerca del documento a enviar
clear e_datos_doc.
e_datos_doc-obj_descr = v_titulo.
e_datos_doc-doc_size = ( v_lineas - 1 ) * 255 + strlen( i_cont_bin ).

* Información del receptor del mensaje
refresh i_destinatario.
clear i_destinatario.
i_destinatario-receiver = v_destinatario.
i_destinatario-rec_type = v_tipo.
append i_destinatario.

* Envio del mail
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = e_datos_doc
put_in_outbox = 'X'
tables
packing_list = i_objpack
contents_bin = i_cont_bin
contents_txt = i_texto
receivers = i_destinatario
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
others = 99.

case sy-subrc.
when 2.
raise documento_no_enviado.
when 4.
raise sin_autorizacion.
when 99.
raise error_interno.
endcase.

endfunction.

*----------------------------------------------------------------------*
***INCLUDE LZGE003F01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form comprobar_orden_spool
*&---------------------------------------------------------------------*
* Comprobar que la orden spool existe y es un formulario
*----------------------------------------------------------------------*
* -->PI_SPOOL Número de orden spool a comprobar
*----------------------------------------------------------------------*
form comprobar_orden_spool using pi_spool.

select single rqdoctype from tsp01
into tsp01-rqdoctype
where rqident = pi_spool.
if not sy-subrc is initial.
raise spool_no_existe.
elseif tsp01-rqdoctype <> 'OTF'.
raise spool_no_es_un_formulario.
endif.

endform. " comprobar_orden_spool

*&---------------------------------------------------------------------*
*& Form llenar_tabla_bin
*&---------------------------------------------------------------------*
* Convertir el spool a PDF (binario)
*----------------------------------------------------------------------*
* -->PI_SPOOL Número de orden spool a tratar
*----------------------------------------------------------------------*
form llenar_tabla_bin using pi_spool.

* Recuperar el spool en formato PDF
call function 'CONVERT_OTFSPOOLJOB_2_PDF'
exporting
src_spoolid = pi_spool
no_dialog = ' '
pdf_destination = 'X'
importing
pdf_bytecount = v_num_bytes
tables
pdf = i_pdf.

* La tabla PDF tiene 134 caracteres de ancho, se pasa a la I_BIN, de 255
refresh i_bin.
clear i_bin.
v_queda = 255.
loop at i_pdf.
if v_queda > 134.
v_long = 134.
else.
v_long = v_queda.
endif.
if v_long > 0.
concatenate i_bin i_pdf+v_offset(v_long) into i_bin.
endif.
v_len = strlen( i_bin ).
if v_len = 255.
append i_bin.
clear i_bin.
v_offset = 134 - v_queda.
if v_offset > 0.
concatenate i_bin i_pdf+v_queda(v_offset) into i_bin.
endif.
v_len = strlen( i_bin ).
clear v_offset.
endif.
v_queda = 255 - v_len.
endloop.
append i_bin.

endform. " llenar_tabla_bin


Espero te sea de utilidad.
Un saludor :D .

vstarke
05/03/10, 15:12:33
eso sirve si en caso el archivo tiene más de 255 caracteres?