Send Email using Oracle Database


UTL_MAIL

The UTL_MAIL package provides a simple API to allow email to be sent from PL/SQL. The package is loaded by running the following scripts.

CONN sys/password AS SYSDBA
@$ORACLE_HOME/rdbms/admin/utlmail.sql
@$ORACLE_HOME/rdbms/admin/prvtmail.plb

In addition the SMTP_OUT_SERVER parameter must be set to identify the SMTP server.

ALTER SYSTEM SET smtp_out_server='smtp.domain.com:port' SCOPE=SPFILE;

With the configuration complete we can now send a mail.

BEGIN
UTL_MAIL.send(sender     => 'me@domain.com',
recipients => 'person1@domain.com,person2@domain.com',
cc         => 'person3@domain.com',
bcc        => 'myboss@domain.com',
subject    => 'UTL_MAIL Test',
message    => 'If you get this message it worked!');
END;
/

The package also supports sending mails with RAW and VARCHAR2 attachments.

One response to “Send Email using Oracle Database”

  1. Fabio says :

    Useful article.
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: