lunes, 5 de mayo de 2014

Envio de correo electronico con OLE2

En este post os voy a comentar como podemos enviar emails en SAP utilizando objetos OLE2. Es una funcionalidad muy interesante. Hay mas opciones pero hoy nos vamos a centrar en esta. Este artículo lo voy a escribir en ingles, es una buena forma de practicar el idioma para mi y para vosotros!!!


OLE2 objects are the milestone of COM technologies in SAP. You can connect any other system such as Outlook, Excel, Word, Adobe PDF from SAP with registering these assembly files of these systems.
You can not use OLE2 objects in background. While using some functions deal with OLE2 objects, there should be a connection to GUI.
OLE2 objects are very usefull while creating our localized applications. Such as you need to create an excel file with suppliying SAP data and so you can draw graphics in excel. We can diversify our examples. Think that you have a word template file. Such as a billing word document. You need to supply the required information to this template file. As a result, you can achieve your word document that was feeded with your SAP information as an output.
In our example, we will show a mail document in foreground. We will attach some documents to this mail. I have managed several document management projects in SAP. Documents are scanned and loaded into network and any document can be shown in SAP with the header information of this document. But, there is requirement that this document should be mailed easiliy. So, the fateful operation is adding the reqired documents to outlook mail message.
We will examine how to use the OLE2 objects from the beginning.
TYPE-POOLS OLE2.

DATA:
APPOUTLOOK TYPE OLE2_OBJECT,
APPITEM TYPE OLE2_OBJECT,
NAMESPACE TYPE OLE2_OBJECT,
ATTACHS TYPE OLE2_OBJECT,
At the first data declaretion, we need to declare the ole2 objects of the outlook. Don’t forget to declare the OLE2 type-pool.
BEGIN OF ITAB_PATHS OCCURS 0,
PATH(255),
END OF ITAB_PATHS,
MAIL_INDEX TYPE I.
Second data declaretion of ITAB_PATHS and MAIL_INDEX is for attaching documents.
CREATE OBJECT APPOUTLOOK 'outlook.application'.
CALL METHOD OF APPOUTLOOK 'GetNameSpace' = NAMESPACE
EXPORTING #1 = 'MAPI'.
CALL METHOD OF APPOUTLOOK 'CreateItem' = APPITEM
EXPORTING #1 = '0'.
GET PROPERTY OF APPITEM 'Attachments' = ATTACHS.
Above, we are creating outlook mail application and getting the mail attachments object.
SET PROPERTY OF APPITEM 'to' = 'xyz@zyx.com'. ” to whom we will send mail
SET PROPERTY OF APPITEM 'cc' = 'xyz@zyx.com; abc@cba.com'. ” to whom we will send mail in cc
SET PROPERTY OF APPITEM 'Subject' = 'The first mail with OLE2'. ” mail subject
MAIL_INDEX = 1.
We are now adding our attachments.
LOOP AT ITAB_PATHS.
CALL METHOD OF ATTACHS 'Add'
EXPORTING
#1 = ITAB_PATHS-PATH
#2 = '1'
#3 = MAIL_INDEX
#4 = ITAB_PATHS-PATH.
MAIL_INDEX = MAIL_INDEX + 1.
ENDLOOP.
It is time to show our mail message.
CALL METHOD OF APPITEM 'Display'.
It is important to free our ole objects.
FREE: ATTACHS, APPITEM, NAMESPACE, APPOUTLOOK.
And, what is the result?



You can comment or contact me for your questions or comments.


No hay comentarios:

Publicar un comentario