Académique Documents
Professionnel Documents
Culture Documents
The utl_smtp utility enables e-mail messages to be sent from the database (PL/S
QL) to any valid e-mail address. This can be very useful in database monitoring
since e-mails can be sent to production support personnel when certain events o
ccur. These events could be anything ranging from space deficits to unauthorize
d database access. Anything that can be monitored can be sent in an e-mail.
< sendmail.sql
BEGIN
c := utl_smtp.open_connection(mailhost, 25); -- SMTP on port 25
utl_smtp.helo(c, mailhost);
utl_smtp.mail(c, msg_from);
utl_smtp.rcpt(c, msg_to);
EXCEPTION
WHEN UTL_SMTP.INVALID_OPERATION THEN
dbms_output.put_line(' Invalid Operation in Mail attempt
using UTL_SMTP.');
WHEN UTL_SMTP.TRANSIENT_ERROR THEN
dbms_output.put_line(' Temporary e-mail issue - try again');
WHEN UTL_SMTP.PERMANENT_ERROR THEN
dbms_output.put_line(' Permanent Error Encountered.');
END;
/
exec send_mail(msg_to=>'dave@oracleutilities.com', -
msg_subject => 'Hello from Oracle', -
msg_text => 'This is the body of the message'-
);
The e-mail will be sent from the database and received by the recipient. Figure
5.2 displays the actual e-mail as delivered to my inbox.