Oracle9i Supplied PL/SQL Packages and Types Reference Release 2 (9.2) Part Number A96612-01 |
|
UTL_SMTP , 3 of 3
The following example illustrates how UTL_SMTP
is used by an application to send e-mail. The application connects to an SMTP server at port 25 and sends a simple text message.
DECLARE c utl_smtp.connection; PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS BEGIN utl_smtp.write_data(c, name || ': ' || header || utl_tcp.CRLF); END; BEGIN c := utl_smtp.open_connection('smtp-server.acme.com'); utl_smtp.helo(c, 'foo.com'); utl_smtp.mail(c, 'sender@foo.com'); utl_smtp.rcpt(c, 'recipient@foo.com'); utl_smtp.open_data(c); send_header('From', '"Sender" <sender@foo.com>'); send_header('To', '"Recipient" <recipient@foo.com>'); send_header('Subject', 'Hello'); utl_smtp.write_data(c, utl_tcp.CRLF || 'Hello, world!'); utl_smtp.close_data(c); utl_smtp.quit(c); EXCEPTION WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN BEGIN utl_smtp.quit(c); EXCEPTION WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN NULL; -- When the SMTP server is down or unavailable, we don't have -- a connection to the server. The quit call will raise an -- exception that we can ignore. END; raise_application_error(-20000, 'Failed to send mail due to the following error: ' || sqlerrm); END;
|
Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|