I have sent mail from Oracle forms using the OLE2 package.
I created an Oracle Form called Mail.fmb. The form contains parameters for "Send To" and "Message". I put the following package spec and package body in the Program Units of the form:
Package spec:
PACKAGE Mailx IS
session OLE2.OBJ_TYPE; /* OLE object handle */
args OLE2.LIST_TYPE; /* handle ot OLE argument list */
PROCEDURE logon ( Profile IN VARCHAR2 DEFAULT NULL);
PROCEDURE logoff (Attch IN BOOLEAN DEFAULT FALSE);
PROCEDURE send ( Recp IN VARCHAR2,
Subject IN VARCHAR2,
Text IN VARCHAR2,
Attch IN VARCHAR2);
PROCEDURE parserecp ( Recp IN VARCHAR2);
END;
Package Body:
PACKAGE BODY Mailx IS
session_outbox OLE2.OBJ_TYPE;
session_outbox_messages OLE2.OBJ_TYPE;
message1 OLE2.OBJ_TYPE;
msg_recp OLE2.OBJ_TYPE;
recipient OLE2.OBJ_TYPE;
msg_attch OLE2.OBJ_TYPE;
attachment OLE2.OBJ_TYPE;
recpname VARCHAR2(255);
x NUMBER := 0;
y NUMBER := 0;
PROCEDURE logon( Profile IN VARCHAR2 DEFAULT NULL) IS
BEGIN
session := OLE2.CREATE_OBJ('mapi.session'); /* create the session object */
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, Profile); /* Specify a valid profile name */
OLE2.INVOKE(session, 'Logon', args); /* to avoid the logon dialog box */
OLE2.DESTROY_ARGLIST(args);
END;
PROCEDURE logoff (attch IN BOOLEAN DEFAULT FALSE) IS
BEGIN
OLE2.INVOKE(session, 'Logoff'); /* Logoff the session and deallocate resources */
OLE2.RELEASE_OBJ(session);
OLE2.RELEASE_OBJ(session_outbox);
OLE2.RELEASE_OBJ(session_outbox_messages);
OLE2.RELEASE_OBJ(message1);
OLE2.RELEASE_OBJ(msg_recp);
OLE2.RELEASE_OBJ(recipient);
if attch then
OLE2.RELEASE_OBJ(msg_attch);
OLE2.RELEASE_OBJ(attachment);
end if;
END;
PROCEDURE send( Recp IN VARCHAR2, Subject IN VARCHAR2, Text IN VARCHAR2, Attch IN VARCHAR2) IS
BEGIN
/* Add a new object message1 to the outbox */
session_outbox := OLE2.GET_OBJ_PROPERTY(session, 'outbox');
session_outbox_messages := OLE2.GET_OBJ_PROPERTY(session_outbox, 'messages');
message1 := OLE2.INVOKE_OBJ(session_outbox_messages, 'Add');
if Subject is not null then
OLE2.SET_PROPERTY(message1, 'subject', Subject);
end if;
if Text is not null then
OLE2.SET_PROPERTY(message1, 'text', Text);
end if;
/* Add a recipient object to the message1.Recipients collection */
msg_recp := OLE2.GET_OBJ_PROPERTY(message1, 'Recipients');
parserecp(recp); --Added for multiple recipients rgm
while recpname is not null loop --Added for multiple recipients
recipient := OLE2.INVOKE_OBJ(msg_recp, 'add');
OLE2.SET_PROPERTY(recipient, 'name', recpname);
OLE2.SET_PROPERTY(recipient, 'type', 1);
OLE2.INVOKE(recipient, 'resolve');
parserecp(recp);
end loop;
x := 0;
y := 0;
/* Add an attachment object to the message1.Attachments collection */
if Attch is not null then
msg_attch := OLE2.GET_OBJ_PROPERTY(message1, 'Attachments');
attachment := OLE2.INVOKE_OBJ(msg_attch, 'add');
OLE2.SET_PROPERTY(attachment, 'name', Attch);
OLE2.SET_PROPERTY(attachment, 'position', 0);
OLE2.SET_PROPERTY(attachment, 'type', 1); /* 1 = MAPI File Data */
OLE2.SET_PROPERTY(attachment, 'source', Attch);
/* Read the attachment from the file */
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, Attch);
OLE2.INVOKE(attachment, 'ReadFromFile', args);
OLE2.DESTROY_ARGLIST(args);
end if;
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 1); /* 1 = save copy */
OLE2.ADD_ARG(args, 0); /* 0 = no dialog */
/* Send the message without any dialog box, saving a copy in the Outbox */
OLE2.INVOKE(message1, 'Send', args);
OLE2.DESTROY_ARGLIST(args);
/* MESSAGE('Message successfully sent'); */
END;
PROCEDURE parserecp (Recp IN VARCHAR2) IS
BEGIN
y := x + 1;
if y <= length(recp) then
x := instr(Recp, ';', y, 1);
if x = 0 then
x := 255;
recpname := substr(Recp, y, length(recp) + 1 - y);
else
recpname := substr(Recp, y, x - y);
end if;
else
recpname := null;
end if;
END;
END;
To send the message, I have a button with the following code:
Mailx.Logon(:profile); 'your outlook profile
Mailx.Send(:to, :subject, :messagetext, :attachment);
If :Attachment Is Null Or :Attachment = '' Then
Mailx.logoff;
Else
Mailx.logoff (TRUE);
End If;
Hope this helps
Dear swapna
Please use following procedure to sent email from outlook
PROCEDURE sendmail
IS
objOutlook OLE2.OBJ_TYPE;
objMail OLE2.OBJ_TYPE;
objArg OLE2.LIST_TYPE;
objAttach OLE2.OBJ_TYPE;
BEGIN
objOutlook := OLE2.CREATE_OBJ(‘Outlook.Application’);
objarg := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(objarg,0);
objMail := OLE2.INVOKE_OBJ(objOutlook,’CreateItem’,objarg);
OLE2.DESTROY_ARGLIST(objarg);
objAttach := OLE2.GET_OBJ_PROPERTY(objmail, ‘Attachments’);
objarg := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(objarg,’c:abc.txt’);
OLE2.SET_PROPERTY(objmail,’To’,:to);
OLE2.SET_PROPERTY(objmail,’Subject’,:subject);
OLE2.SET_PROPERTY(objmail,’Body’,:body);
OLE2.INVOKE(objattach, ‘Add’, objarg);
OLE2.INVOKE(objmail,’Send’);
OLE2.INVOKE(objmail,’Display’);
OLE2.RELEASE_OBJ(objmail);
OLE2.RELEASE_OBJ(objOutlook);
OLE2.DESTROY_ARGLIST(objarg);
Message(‘mail sent.’);
Message(‘mail sent.’);
EXCEPTION
WHEN OTHERS THEN
Message(‘not sent.’);
Message(‘not sent.’);
END;
Wow, great, thorough answers! Hiswapna, be sure to let us know if these answers helped you.
Jenny
Community Manager
Use this code to hande multiple atachments:
PROCEDURE sendmail ( — creado a razon de cambios en outlook 2010
recp IN VARCHAR2,
subject IN VARCHAR2,
text IN VARCHAR2,
attch IN VARCHAR2,
natach IN NUMBER,
exito OUT BOOLEAN
)
IS
objoutlook ole2.obj_type;
objmail ole2.obj_type;
objarg ole2.list_type;
objattach ole2.obj_type;
BEGIN
objoutlook := ole2.create_obj (‘Outlook.Application’);
objarg := ole2.create_arglist;
ole2.add_arg (objarg, 0);
objmail := ole2.invoke_obj (objoutlook, ‘CreateItem’, objarg);
ole2.destroy_arglist (objarg);
–
IF NVL (natach, 0) != 0
THEN
objattach := ole2.get_obj_property (objmail, ‘Attachments’);
FOR i IN 1 .. natach
LOOP
objarg := ole2.create_arglist;
ole2.add_arg (objarg, ld_util.decodi (attch, i));
ole2.invoke (objattach, ‘Add’, objarg);
ole2.destroy_arglist (objarg);
END LOOP;
END IF;
ole2.set_property (objmail, ‘To’, recp);
ole2.set_property (objmail, ‘Subject’, subject);
ole2.set_property (objmail, ‘Body’, text);
–
ole2.invoke (objmail, ‘Send’);
ole2.invoke (objmail, ‘Display’);
ole2.RELEASE_OBJ (objmail);
ole2.RELEASE_OBJ (objoutlook);
EXCEPTION
WHEN OTHERS
THEN
MESSAGE (‘Error enviando correo ‘ || SQLERRM);
MESSAGE (‘ ‘);
END;
hey gays thanks for this aports, Jviquez!! i’m compiling your code in forms 6i but i have a problem (error) in te sentence ” util.decodi (attch, i)); ” ..mus be declared.
can you help me please? mi mail es cwsv_9@hotmail.com
I need a code to attachment 6 files.txt and send by mail.