Oracle Management Cloud

Introduction to Oracle Management Cloud We have been seeing so many products of Oracle off late. A new suite from Oracle named Oracle Manage...

Thursday, March 21, 2013

How to send mail using utl_mail from PL/SQL?

Aim: To send a mail using utl_mail from SQL.

Procedure:
$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus '/as sysdba'

SQL> @utlmail.sql

Package created.

Synonym created.

SQL> @prvtmail.plb

Package created.

Package body created.

Grant succeeded.

Package body created.

No errors.
SQL> GRANT EXECUTE ON UTL_MAIL TO PUBLIC;

Grant succeeded.

Test:


SQL> BEGIN
  2    EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''mail.testhost.com''';
  3    UTL_MAIL.send(sender => 'vbadam@testhost.com',
  4                  recipients => 'veda.santosh@gmail.com',
  5                     subject => 'Test Mail',
  6                     message => 'Hello World',
  7                   mime_type => 'text; charset=us-ascii');
  8  END;
  9  /

PL/SQL procedure successfully completed.



And a test mail is received at veda.santosh@gmail.com

No comments:

Post a Comment

Most Viewed Posts