send mail proceedure

set serveroutput on;

DECLARE
   -- Configure these variables
   v_mail_host           VARCHAR2(30) := '<smtp_server_domian>';
   v_mail_port           NUMBER := 25;
   v_to                  VARCHAR2(80) := '<your_sending_mail.id>';
   -- Do not touch
   v_from                VARCHAR2(80);
   v_subj                VARCHAR2( 100) := 'test subj ' || TO_CHAR( SYSDATE, 'YYYY-MM-DD HH24:MI:SS');
   v_msg                 VARCHAR2( 100) := 'test msg';
   v_mail_conn           utl_smtp.connection;
   crlf                  VARCHAR2(2) := CHR(13) || CHR(10);
BEGIN
   -- Set from with dbname
   SELECT 'noreply@' || LOWER( GLOBAL_NAME)
     INTO v_from
     FROM GLOBAL_NAME;
   -- Send email
   v_mail_conn := utl_smtp.open_connection( v_mail_host, v_mail_port);
   utl_smtp.helo( v_mail_conn, v_mail_host);
   utl_smtp.mail( v_mail_conn, v_from);
   utl_smtp.rcpt( v_mail_conn, v_to);
   utl_smtp.data( v_mail_conn,
                  'Date: ' || TO_CHAR(SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
                  'From: ' || v_from || crlf ||
                  'Subject: ' || v_subj || crlf ||
                  'To: ' || v_to || crlf ||
                  crlf ||
                  v_msg || crlf);
   utl_smtp.quit( v_mail_conn);
END;
/

Comments

Popular posts from this blog

Installing DBMS_JAVA package in Oracle and calling UTL_DBWS web services through Oracle database

Starting background process GTX4 and GLOBAL_TXN_PROCESSES

stick the job to the specific instance in Oracle RAC