Oracle Database 10g has made it easier than ever
before to interface PL/SQL with e-mail.
UPDATE: See
these other important notes on
sending e-mail from Oracle.
The utl_mail package makes it easy for a PL/SQL programmer to send
e-mail from Oracle. The utl_mail package is different from the
utl_smtp package because you don't need to understand the internal
machinations of the SMTP protocol.
This, and other new PL/SQL features are fully
described in Dr. Hall's book. "Oracle
job scheduling".
The utl_mail utility is also described in the
book "Oracle10g New Features".
According to the 10g new
features book, utl_mail interfaces with the smtp_out_server
parameter to specify the outbound destination
for e-mail:
"smtp_out_server
specifies the SMTP host and port to
which utl_mail
delivers outbound E-mail. Multiple servers may be specified,
separated by commas.
If the first server in the list is
unavailable, then utl_mail
tries the second server, and so on."
Here is a PL/SQL example of using utl_mail to
send an e-mail message:
Here
is a simple example of how to send email using utl_mail.
Replace the obvious text prompts for real data. If one does not know
one’s mail server, send an email to oneself and look at the header
data, or ask the system administrator.
ALTER SYSTEM SET smtp_out_server = 'mailserver.domain.com';
DECLARE
vSender VARCHAR2(30) := 'sender@somewhere.com';
vRecip
VARCHAR2(30) := 'your.name@domain.com';
vSubj
VARCHAR2(50) := 'Enter the subject here';
vMesg
VARCHAR2(4000) := 'Enter the body';
vMType
VARCHAR2(30) := 'text/plain; charset=us-ascii';
BEGIN
utl_mail.send
(vSender, vRecip, NULL, NULL, vSubj, vMesg,
vMType, NULL);
END;
/