Oracle9i Supplied PL/SQL Packages and Types Reference Release 1 (9.0.1) Part Number A89852-02 |
|
UTL_SMTP
is designed for sending e-mail over Simple Mail Transfer Protocol (SMTP). It does not have the functionality to implement an SMTP server for mail clients to send e-mail using SMTP.
Many interfaces to the SMTP package appear as both a function and a procedure. The functional form returns the reply from the server for processing by the client. The procedural form discards the reply but raises an exception if the reply indicates a transient (400-range reply code) or permanent error (500-range reply code).
Note that the original SMTP protocol communicates using 7-bit ASCII. Using UTL_SMTP,
all text data (in other words, those in VARCHAR2
) will be converted to US7ASCII before it is sent over the wire to the server. Some implementations of SMTP servers that support SMTP extension 8BITMIME [RFC1652] support full 8-bit communication between client and server.
The body of the DATA
command may be transferred in full 8 bits, but the rest of the SMTP command and response should be in 7 bits. When the target SMTP server supports 8BITMIME extension, users of multibyte databases may convert their non-US7ASCII, multibyte VARCHAR2
data to RAW
and use the write_raw_data()
API to send multibyte data using 8-bit MIME encoding.
Also, note that UTL_SMTP
provides API for SMTP communication as specified in RFC821. The package does not provide API to format the content of the message according to RFC 822 (for example, setting the subject of an electronic mail). It is the user's responsibility to format the message appropriately.
This chapter discusses the following topics:
Note : RFC documents are "Request for Comments" documents that describe proposed standards for public review on the Internet. For the actual RFC documents, please refer to:
|
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.
UTL_SMTP.send_mail (sender IN VARCHAR2, recipient IN VARCHAR2, message IN VARCHAR2)IS mailhost VARCHAR2(30) := 'mailhost.mydomain.com'; mail_conn utl_smtp.connection; BEGIN mail_conn := utl_smtp.open_connection(mailhost, 25); utl_smtp.helo(mail_conn, mailhost); utl_smtp.mail(mail_conn, sender); utl_smtp.rcpt(mail_conn, recipient); utl_smtp.data(mail_conn, message); utl_smtp.quit(mail_conn); EXCEPTION WHEN OTHERS THEN -- Handle the error END;
Table 82-1 lists the exceptions that can be raised by the API of the UTL_SMTP
package. The network error is transferred to a reply code of 421- service not available.
No limitation or range-checking is imposed by the API. However, you should be aware of the following size limitations on various elements of SMTP. Sending data that exceed these limits may result in errors returned by the server.
The following is a list of the SMTP reply codes.
Subprogram | Description |
---|---|
This is a PL/SQL record type used to represent a SMTP connection. |
|
PL/SQL record types used to represent an SMTP reply line. |
|
Opens a connection to an SMTP server. |
|
Performs a generic SMTP command. |
|
Performs initial handshaking with SMTP server after connecting. |
|
Performs initial handshaking with SMTP server after connecting, with extended information returned. |
|
Initiates a mail transaction with the server. The destination is a mailbox. |
|
Specifies the recipient of an e-mail message. |
|
Specifies the body of an e-mail message. |
|
"open_data(), write_data(), write_raw_data(), close_data() Functions" |
Provide more fine-grain control to the data() API. |
Aborts the current mail transaction. |
|
Verifies the validity of a destination e-mail address. |
|
The null command. |
|
Terminates an SMTP session and disconnects from the server. |
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|