Home » Developer & Programmer » Forms » Send Email from forms
Send Email from forms [message #153352] Sat, 31 December 2005 23:07 Go to next message
hiswapna
Messages: 6
Registered: December 2005
Location: Hyderabad
Junior Member
Hi

I dont have much information on how to send mails from oracle.

My problem description is
i have to add a button in my form, on clicking it it should send a mail to the user.

How do i achieve this.

Thanks & Regards
Swapna
icon2.gif  Re: Send Email from forms [message #153364 is a reply to message #153352] Sun, 01 January 2006 11:12 Go to previous messageGo to next message
gssunil
Messages: 7
Registered: January 2006
Location: Chicago
Junior Member

Hi hiSwapna,

The code here is from the archives of forum which I have used in my form

If Outlook is configured as Mail server this code should work.

--------------------------------------------------------
DECLARE
objOutlook OLE2.OBJ_TYPE;
objMail OLE2.OBJ_TYPE;
objArg OLE2.LIST_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);

OLE2.SET_PROPERTY(objmail,'To',:TO);
OLE2.SET_PROPERTY(objmail,'Subject',:SUBJECT);
OLE2.SET_PROPERTY(objmail,'Body',:BODY);

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

END;

----------------------------------------

Code this on pressing Send Button which collects information of e-mail parameters from To,Subject and Body.


Regards
Sunil

PS: Happy New Year and happy coding.
Cool
Re: Send Email from forms [message #153380 is a reply to message #153364] Sun, 01 January 2006 23:31 Go to previous messageGo to next message
hiswapna
Messages: 6
Registered: December 2005
Location: Hyderabad
Junior Member
Hi Sunil,

I have used the following bkend procedure to send a simple mail


CREATE OR REPLACE PROCEDURE SEND_MAIL (
msg_from varchar2 := 'oracle',
msg_to varchar2,
msg_subject varchar2 := 'E-Mail message from your database',
msg_text varchar2 := '' )
IS
c utl_tcp.connection;
rc integer;
BEGIN
c := utl_tcp.open_connection('127.0.0.1', 25); -- open the SMTP port 25 on local machine
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'HELO localhost');
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'MAIL FROM: '||msg_from);
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'RCPT TO: '||msg_to);
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'DATA'); -- Start message body
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'Subject: '||msg_subject);
rc := utl_tcp.write_line(c, '');
rc := utl_tcp.write_line(c, msg_text);
rc := utl_tcp.write_line(c, '.'); -- End of message body
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'QUIT');
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
utl_tcp.close_connection(c); -- Close the connection
EXCEPTION
when others then
raise_application_error(
-20000, 'Unable to send e-mail message from pl/sql because of: '||
sqlerrm);
END;




exec send_mail(msg_to =>'hiswapna@gmail.com',msg_text=>'Look Ma, I can send mail from plsql');


and I'm getting the following error message
how do i fix this bug

BEGIN send_mail(msg_to =>'hiswapna@gmail.com',msg_text=>'Look Ma, I can send mail from plsql'); END;

*
ERROR at line 1:
ORA-20000: Unable to send e-mail message from pl/sql because of: ORA-29260:
network error: TNS:no listener
ORA-06512: at "CHINNAGS.SEND_MAIL", line 30
ORA-06512: at line 1

Regards
Swapna
Re: Send Email from forms [message #153501 is a reply to message #153380] Mon, 02 January 2006 22:50 Go to previous message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Also review the thread http://www.orafaq.com/forum/m/129443/67467/?srch=email#msg_129443

David
Previous Topic: Hiding Status Bar in forms 6i - Urgent
Next Topic: lov passing throug parameters
Goto Forum:
  


Current Time: Wed Oct 01 02:02:01 CDT 2014

Total time taken to generate the page: 0.10802 seconds