|
|
|
|
Re: how to send a mail using PL/SQL procedure [message #233883 is a reply to message #233765] |
Fri, 27 April 2007 20:07 |
kdipankar
Messages: 9 Registered: December 2006
|
Junior Member |
|
|
Hi,
Pls find a sample code below.
DECLARE
l_mailhost VARCHAR2(64) := 'mail.mycompany.com';
l_from VARCHAR2(64) := 'me@mycompany.com';
l_subject VARCHAR2(64) := 'Test Mail';
l_to VARCHAR2(64) := 'you@mycompany.com';
l_mail_conn UTL_SMTP.connection;
BEGIN
l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
UTL_SMTP.helo(l_mail_conn, l_mailhost);
UTL_SMTP.mail(l_mail_conn, l_from);
UTL_SMTP.rcpt(l_mail_conn, l_to);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
FOR i IN 1 .. 10 LOOP
UTL_SMTP.write_data(l_mail_conn, 'This is a test message. Line ' || To_Char(i) || Chr(13));
END LOOP;
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
END;
/
The UTL_SMTP package requires Jserver which can be installed by running the following scripts as SYS:
SQL> @$ORACLE_HOME/javavm/install/initjvm.sql
SQL> @$ORACLE_HOME/rdbms/admin/initplsj.sql
|
|
|