I wrote this function from a source which was shared on internet, so I share it too...
Christian
Code:
-- Code is self explaining...
-- dialog is 1: mail is displayed and user can modify it
-- dialog != 1: mail is not displayed, it is sent
-- Text can not be HTML, only basic text
FUNCTION Send_a_mail( Recp IN varchar2,
Subject IN varchar2,
Text IN varchar2,
Attch IN varchar2,
dialog IN number ) RETURN NUMBER
IS
objOutlook OLE2.OBJ_TYPE;
objMail OLE2.OBJ_TYPE;
objArg OLE2.LIST_TYPE;
objAttach OLE2.OBJ_TYPE;
BEGIN
-- Connect to Outlook
objOutlook := OLE2.CREATE_OBJ('Outlook.Application');
-- Create a new Mail
objarg := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(objarg,0);
objMail := OLE2.INVOKE_OBJ(objOutlook,'CreateItem',objarg);
OLE2.DESTROY_ARGLIST(objarg);
-- Join a file (remove this if you don't need)
objAttach := OLE2.GET_OBJ_PROPERTY(objmail, 'Attachments');
objarg := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(objarg, Attch ); -- filename
OLE2.INVOKE(objattach, 'Add', objarg);
OLE2.DESTROY_ARGLIST(objarg);
-- Set text items
OLE2.SET_PROPERTY(objmail,'To',Recp);
OLE2.SET_PROPERTY(objmail,'Subject',Subject);
OLE2.SET_PROPERTY(objmail,'Body',Text);
-- Send or display
IF dialog = 1 THEN
OLE2.INVOKE(objmail, 'Display');
ELSE
OLE2.INVOKE(objmail, 'Send');
END IF;
-- Free ressources
OLE2.RELEASE_OBJ(objmail);
OLE2.RELEASE_OBJ(objOutlook);
return 0;
END;
Christian