0% found this document useful (0 votes)
1K views5 pages

Email Through Oracle Forms

This document contains code for automating email generation and sending from Outlook using OLE objects in Oracle Forms. It declares Outlook application and mail item objects, gets the recipients collection, adds recipients, sets mail properties like subject and body, attaches a file, and sends the email. It also contains error handling for if Outlook is not configured or accessible.

Uploaded by

deepankar04
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views5 pages

Email Through Oracle Forms

This document contains code for automating email generation and sending from Outlook using OLE objects in Oracle Forms. It declares Outlook application and mail item objects, gets the recipients collection, adds recipients, sets mail properties like subject and body, attaches a file, and sends the email. It also contains error handling for if Outlook is not configured or accessible.

Uploaded by

deepankar04
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

D

Declare

/*declaration of the Outlook Object Variables*/


application ole2.OBJ_TYPE;
hMailItem ole2.OBJ_TYPE;
hRecipients ole2.OBJ_TYPE;
recipient ole2.OBJ_TYPE;

/*declaration of the argument list*/


args OLE2.LIST_TYPE;

begin
/*create the Application Instance*/
application:=ole2.create_obj('Outlook.Application');

/*create a Mail Instance by calling CreateItem Method and giving argument 0


with
it,
you can find the item types in the explanation of the CreateItem Method
(0=olMailItem,1=olAppointmentItem, ?)*/
args:=ole2.create_arglist;
ole2.add_arg(args,0);
hMailItem:=ole2.invoke_obj(application,'CreateItem',args);
ole2.destroy_arglist(args);

/*Get the Recipients property of the MailItem object:


Returns a Recipients collection that represents all the Recipients for the
Outlook item*/
args:=ole2.create_arglist;
hRecipients:=ole2.get_obj_property(hMailItem,'Recipients',args);
ole2.destroy_arglist(args);

/*Use the Add method to create a recipients Instance and add it to the
Recipients collection*/
args:=ole2.create_arglist;
ole2.add_arg(args,'david.[Email address protected]
recipient:=ole2.invoke_obj(hRecipients,'Add',args);

/* put the property Type of the recipient Instance to value needed


(0=Originator,1=To,2=CC,3=BCC)*/
ole2.set_property(recipient,'Type',1);
ole2.destroy_arglist(args);

/* put the property Type of the recipient Instance to value needed


(0=Originator,1=To,2=CC,3=BCC)*/
ole2.set_property(recipient,'Type',2);
ole2.destroy_arglist(args);

/*Resolve the Recipients collection*/


args:=ole2.create_arglist;
ole2.invoke(hRecipients,'ResolveAll',args);

/*set the Subject and Body properties*/


ole2.set_property(hMailItem,'Subject','Volumn Partner '||:d_name||'
configured.');
ole2.set_property(hMailItem,'Body','Volumn Partner '||:d_name||' was
successfully setup on '||:d_time||'. The PSOURCE ID is: '||:d_pid);

/*Save the mail*/


ole2.invoke(hMailItem,'Save',args);
ole2.destroy_arglist(args);

/*Send the mail*/


args:=ole2.create_arglist;
ole2.invoke(hMailItem,'Send',args);
ole2.destroy_arglist(args);

/*Release all your Instances*/


release_obj(application);
release_obj(hRecipients);
release_obj(recipient);
release_obj(hMailItem);

e
end;

#################### OTHER
##################################################################################
#
#############

D
Declare

objOutlook CLIENT_OLE2.OBJ_TYPE;
objMail CLIENT_OLE2.OBJ_TYPE;
objArg CLIENT_OLE2.LIST_TYPE;
objAttach CLIENT_OLE2.OBJ_TYPE;

B
BEGIN

objOutlook := CLIENT_OLE2.CREATE_OBJ('Outlook.Application');

-- Previous example usually used 'mapi.session' but this doesn't work correctly
--anymore.
objarg := CLIENT_OLE2.CREATE_ARGLIST;
CLIENT_OLE2.ADD_ARG(objarg,0);

objMail := CLIENT_OLE2.INVOKE_OBJ(objOutlook,'CreateItem', objarg);


CLIENT_OLE2.DESTROY_ARGLIST(objarg);

objAttach := CLIENT_OLE2.GET_OBJ_PROPERTY(objmail, 'Attachments');

objarg := CLIENT_OLE2.CREATE_ARGLIST;
CLIENT_OLE2.ADD_ARG(objarg,'c:\temp\test.txt'); -- filename

CLIENT_OLE2.SET_PROPERTY(objmail,'To','Joe.Friday@ oracle.com');

CLIENT_OLE2.SET_PROPERTY(objmail,'Subject','Email sent from Oracle Forms 9i');


CLIENT_OLE2.SET_PROPERTY(objmail,'Body','This is an email that was sent using
CLIENT_OLE2 from Oracle forms 9i');
CLIENT_OLE2.INVOKE(objattach, 'Add', objarg);
CLIENT_OLE2.INVOKE(objmail,'Send');

CLIENT_OLE2.RELEASE_OBJ(objmail);
CLIENT_OLE2.RELEASE_OBJ(objOutlook);
C
CLIENT_OLE2.DESTROY_ARGLIST(objarg);

E
END;

############## OTHER
##################################################################################
####################
DECLARE
objOutlook client_ole2.OBJ_TYPE;
objMail client_ole2.OBJ_TYPE;
objArg client_ole2.LIST_TYPE;
v_mail_id varchar2(100);
generated_by_name varchar2(300);
var_new varchar2(1000);
v

------
NameSpace client_ole2.OBJ_TYPE; -- documents collection
Folders client_ole2.OBJ_TYPE;
MailItem client_ole2.OBJ_TYPE;
MailItem2 client_ole2.OBJ_TYPE;
Attachments client_ole2.OBJ_TYPE;
Attachment_dummy client_ole2.OBJ_TYPE;
OutlookApp client_ole2.OBJ_TYPE;
OLEPARAM client_ole2.list_type;
pl_id ParamList;
pl_name VARCHAR2(10) := 'tempdata';
application client_ole2.OBJ_TYPE;
hMailItem client_ole2.OBJ_TYPE;
args client_ole2.LIST_TYPE;
msg_attch client_ole2.OBJ_TYPE;
attachment client_ole2.OBJ_TYPE;
des VARCHAR2(80) := 'FILE_NAME';
attch VARCHAR2(80) ;
v_x boolean;
--desname varchar2(300) :=
'L:\oraclefiles\temp\'||:blk_liberty8d.line_srno||'.pdf';
v_pdf_file_name varchar2(500);
vcounter number := 0;
v
-
------

cursor c_on_gen is select A.EMP_NO,B.PMAIL_ID from LIBERTY_8DFORM_AUTH


A,emp_master B
WHERE A.EMP_NO=B.EMP_NO
AND A.LIBERTY_8DFORM_MAIL_ON_GEN='Y'
AND
A B.SEPERATION_DATE>SYSDATE;

B
BEGIN

--if :global.emp_no=10092 then


--run_report_web('/secure/iso/reports/lib_mail.rdf','P_LINE_SRNO='||:BLK_LIBERTY
8D.LINE_SRNO||'&P_SITE_ID='||:BLK_LIBERTY8D.SITE_ID||'&desname='||'C:\SECURE\'||:B
LK_LIBERTY8D.LINE_SRNO||'.pdf'||'&desformat=pdf&destype=file&paramform=no');
-
--else

-------
-
v_pdf_file_name :='l:\oraclefiles\temp\'||:blk_liberty8d.line_srno||'.pdf';
v_x :=webutil_file.delete_file(v_pdf_file_name);
run_report_web('/secure/iso/reports/lib_mail.rdf','P_LINE_SRNO='||:BLK_LIBERTY8D
.LINE_SRNO||'&P_SITE_ID='||:BLK_LIBERTY8D.SITE_ID||'&desname='||'/nfserver/oraclef
iles/temp/'||:BLK_LIBERTY8D.LINE_SRNO||'.pdf'||'&desformat=pdf&destype=file&paramf
orm=no');
--end if;

-------

loop
v_x:=webutil_file.file_exists(v_pdf_file_name);
if v_x then
i
exit;
end if;
end loop;
e

for j in c_on_gen loop


var_new:=var_new||';'||j.pmail_id;
end loop;
e

select emp_name into generated_by_name from emp_master


where emp_no=:blk_liberty8d.generated_by;
w

if (:dummy_approved= 'N' and (nvl(:blk_liberty8d.APPROVED_YN,'N')='Y')) then


i

o
objOutlook := client_ole2.CREATE_OBJ('Outlook.Application');
--------
/*OLEPARAM := client_ole2.CREATE_ARGLIST;
client_ole2.ADD_ARG(OLEPARAM,'MAPI');
NameSpace := client_ole2.INVOKE_OBJ(OutlookApp,'GetNameSpace',OLEPARAM);
client_ole2.DESTROY_ARGLIST( OLEPARAM );*/
-
-------

objarg := client_ole2.CREATE_ARGLIST;
client_ole2.ADD_ARG(objarg,0);
objMail := client_ole2.INVOKE_OBJ(objOutlook,'CreateItem',objarg);
c
client_ole2.DESTROY_ARGLIST(objarg);

client_ole2.SET_PROPERTY(objmail,'To',var_new||';'||'ESL-CSS@entity-
solutions.com');
client_ole2.SET_PROPERTY(objmail,'Subject','8D Approved');
client_ole2.SET_PROPERTY(objmail,'Body','8D Approved by '||:global.frm_emp_name||
chr(10)||'which was generated by '||generated_by_name||chr(10)||
' No. '||:blk_liberty8d.LINE_SRNO||chr(10)||
' Dated '||:blk_liberty8d.date_line_stop||chr(10)||
' Line '||:blk_liberty8d.product_lineno||chr(10)||
' FAILURE_STAGE '||:blk_liberty8d.failure_stage||chr(10)||
' Product '||:blk_liberty8d.part_name||chr(10)||
' Problem description '||:blk_liberty8d.problem_desc||chr(10)||
' Note:-This message was Automaticaly generated by SML ERP'||chr(10)||chr(10)||
chr(10)||
'[CONFIDENTIAL]');

------
Attachments := client_ole2.GET_OBJ_PROPERTY(objmail,'Attachments');

objarg := client_ole2.CREATE_ARGLIST;

client_ole2.ADD_ARG(objarg,v_pdf_file_name);
Attachment_dummy := client_ole2.INVOKE_OBJ(Attachments,'Add',objarg);

client_ole2.DESTROY_ARGLIST( objarg );

------
client_ole2.INVOKE(objmail,'Send');
client_ole2.INVOKE(objmail,'Display');
client_ole2.RELEASE_OBJ(objmail);
client_ole2.RELEASE_OBJ(objOutlook);

end if;

--v_x :=webutil_file.delete_file(v_pdf_file_name);
exception when others then
showalert('Microsoft Outlook is not configured or Not Accessible.Automatic Email
will not Be Generated');

END;
----------------------------------------------------------------------------------
----------------------------------

You might also like