FUNCTION ZCORREO.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" REFERENCE(CORREO2) TYPE C
*" REFERENCE(ADJUNTO2) TYPE C
*"----------------------------------------------------------------------
data:
correo(50) type c,
adjunto LIKE RLGRAP-FILENAME.
correo = correo2.
adjunto = adjunto2.
* AT SELECTION-SCREEN ON VALUE-REQUEST FOR adjunto.
* CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
* EXPORTING
* STATIC = 'X'
* MASK = ''
* CHANGING
* FILE_NAME = adjunto.
*
*start-of-selection.
TYPE-POOLS : ole2.
DATA: appoutlook TYPE ole2_object.
DATA: appout2 TYPE ole2_object.
DATA: appitem TYPE ole2_object.
DATA: namespace TYPE ole2_object.
DATA: attachments TYPE ole2_object.
DATA: frace01(45), frace02(45).
DATA: p_subj(20) TYPE c.
DATA: p_body TYPE string.
* Crear objeto OLE : outlook.application
CREATE OBJECT appoutlook 'outlook.application'.
* Mensajes vía MAPI
CALL METHOD OF appoutlook 'GetNameSpace' = namespace
EXPORTING
#1 = 'MAPI'.
* Crea objeto nuevo ITEM ( nuevo mensaje )
CALL METHOD OF appoutlook 'CreateItem' = appitem
EXPORTING
#1 = '0'.
* Propiedades TO , SUBJECT y BODY
SET PROPERTY OF appitem 'To' = correo.
* CONCATENATE p_subj 'OC: ' itab-ebeln INTO p_subj
*SEPARATED BY space.
SET PROPERTY OF appitem 'Subject' = 'Email Automatico'.
CONCATENATE '' 'Mensaje enviado de manera automatica '
INTO p_body.
SET PROPERTY OF appitem 'Body' = p_body.
* Se adjunta el archivo
if adjunto is not initial.
CALL METHOD OF appitem 'Attachments' = attachments.
CALL METHOD OF attachments 'Add'
EXPORTING
#1 = adjunto.
endif.
* Envíar directamente
CALL METHOD OF appitem 'Send'.
*Se muestra la pantalla del outlook
*CALL METHOD OF appitem 'Display'.
* Libera Espacio del objeto
FREE OBJECT attachments.
FREE OBJECT appitem.
FREE OBJECT namespace.
FREE OBJECT APPOUTLOOK.
* Cierra Outlook ( solo si se quiere que quede cerrado )
CALL METHOD OF appoutlook 'Quit'.
*en caso que quieras ejecutar outlook
*CALL FUNCTION 'WS_EXECUTE'
* EXPORTING
** commandline = commandline
* program = 'OUTLOOK.EXE'
* EXCEPTIONS
* frontend_error = 1
* no_batch = 2
* prog_not_found = 3
* illegal_option = 4
* OTHERS = 5.
*
* IF sy-subrc > 0.
* RAISE execution_failed.
* ENDIF.
*
MESSAGE s000(38) WITH 'Proceso email finalizado... '.
*
ENDFUNCTION.
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario