Sending Mail From An 11G Oracle Database
Sending Mail From An 11G Oracle Database
Sending Mail From An 11G Oracle Database
Oracle 11g first introduced the utl_mail package, which provides a simpler and more intuitive email API
through oracle pipe. The package is loaded by running the following scripts as the SYSUSER
1- SQL> @ORACLE_HOME/rdbms/admin/utlmail.sql
2- SQL>@ORACLE_HOME/rdbms/admin/prvtmail.plb
3- SQL> grant execute on utl_mail TO public;
With the configuration complete, it is now possible to send an email using the send
procedure.
BEGIN
UTL_MAIL.SEND (SENDER
RECIPIENTS
SUBJECT
MESSAGE
=>
END;
The code related to the job needs to be placed into a database procedure which captures errors using an
exception handler and sends the appropriate email. The following procedure is the Oracle 11g
equivalent of the one used in the utl_smtp example.
V_mail_host
V_sender
V_to
BEGIN
Dbms_stats.gather_database_stats (cascade
EXCEPTION
When others then
Utl_mail.send (Sender =>V_sender, Recipients =>V_to, Subject=>Error, Message=>Failed: ||
sqlerrm);
END;
In order to send mails in Oracle 11g you will need to take care of several steps.
They are not default installed in the database (11g). You need to actually install the UTL_MAIL package.
SQL> @ORACLE_HOME/rdbms/admin/utlmail.sql
SQL> @ORACLE_HOME/rdbms/admin/prvtmail.plb
SQL> grant execute on utl_mail TO public;
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (acl
=> mail_access.xml,
=> PUBLIC,
Is_grant
=> true,
Privilege
=> connect);
END;
=> mail_access.xml,
host
lower_port
=> 25,
upper_port
=> 25);
Commit;
END;
AS
L_mail_conn UTL_SMTP. Connection;
BEGIN
END;
P_from
P_message
P_host