|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.oroinc.net.SocketClient | +--com.oroinc.net.smtp.SMTP
SMTP provides the basic the functionality necessary to implement your own SMTP client. To derive the full benefits of the SMTP class requires some knowledge of the FTP protocol defined in RFC 821. However, there is no reason why you should have to use the SMTP class. The SMTPClient class, derived from SMTP, implements all the functionality required of an SMTP client. The SMTP class is made public to provide access to various SMTP constants and to make it easier for adventurous programmers (or those with special needs) to interact with the SMTP protocol and implement their own clients. A set of methods with names corresponding to the SMTP command names are provided to facilitate this interaction.
You should keep in mind that the SMTP server may choose to prematurely
close a connection for various reasons. The SMTP class will detect a
premature SMTP server connection closing when it receives a
SMTPReply.SERVICE_NOT_AVAILABLE response to a command.
When that occurs, the SMTP class method encountering that reply will throw
an
SMTPConnectionClosedException .
SMTPConectionClosedException
is a subclass of IOException
and therefore need not be
caught separately, but if you are going to catch it separately, its
catch block must appear before the more general IOException
catch block. When you encounter an
SMTPConnectionClosedException , you must disconnect the connection with
disconnect()
to properly clean up the system resources used by SMTP. Before
disconnecting, you may check the
last reply code and text with
getReplyCode ,
getReplyString ,
and getReplyStrings.
Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can also throw a MalformedServerReplyException , which is a subclass of IOException. A MalformedServerReplyException will be thrown when the reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful manner despite attempts to be as lenient as possible.
SMTPClient
,
SMTPConnectionClosedException
,
MalformedServerReplyException
Field Summary | |
protected ProtocolCommandSupport |
_commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents. |
static int |
DEFAULT_PORT
The default SMTP port (25). |
Fields inherited from class com.oroinc.net.SocketClient |
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL |
Constructor Summary | |
SMTP()
The default SMTP constructor. |
Method Summary | |
protected void |
_connectAction_()
Initiates control connections and gets initial reply. |
void |
addProtocolCommandListener(ProtocolCommandListener listener)
Adds a ProtocolCommandListener. |
int |
data()
A convenience method to send the SMTP DATA command to the server, receive the reply, and return the reply code. |
void |
disconnect()
Closes the connection to the SMTP server and sets to null some internal data so that the memory may be reclaimed by the garbage collector. |
int |
expn(java.lang.String name)
A convenience method to send the SMTP VRFY command to the server, receive the reply, and return the reply code. |
int |
getReply()
Fetches a reply from the SMTP server and returns the integer reply code. |
int |
getReplyCode()
Returns the integer value of the reply code of the last SMTP reply. |
java.lang.String |
getReplyString()
Returns the entire text of the last SMTP server response exactly as it was received, including all end of line markers in NETASCII format. |
java.lang.String[] |
getReplyStrings()
Returns the lines of text from the last SMTP server response as an array of strings, one entry per line. |
int |
helo(java.lang.String hostname)
A convenience method to send the SMTP HELO command to the server, receive the reply, and return the reply code. |
int |
help()
A convenience method to send the SMTP HELP command to the server, receive the reply, and return the reply code. |
int |
help(java.lang.String command)
A convenience method to send the SMTP HELP command to the server, receive the reply, and return the reply code. |
int |
mail(java.lang.String reversePath)
A convenience method to send the SMTP MAIL command to the server, receive the reply, and return the reply code. |
int |
noop()
A convenience method to send the SMTP NOOP command to the server, receive the reply, and return the reply code. |
int |
quit()
A convenience method to send the SMTP QUIT command to the server, receive the reply, and return the reply code. |
int |
rcpt(java.lang.String forwardPath)
A convenience method to send the SMTP RCPT command to the server, receive the reply, and return the reply code. |
void |
removeProtocolCommandistener(ProtocolCommandListener listener)
Removes a ProtocolCommandListener. |
int |
rset()
A convenience method to send the SMTP RSET command to the server, receive the reply, and return the reply code. |
int |
saml(java.lang.String reversePath)
A convenience method to send the SMTP SAML command to the server, receive the reply, and return the reply code. |
int |
send(java.lang.String reversePath)
A convenience method to send the SMTP SEND command to the server, receive the reply, and return the reply code. |
int |
sendCommand(int command)
Sends an SMTP command with no arguments to the server, waits for a reply and returns the numerical response code. |
int |
sendCommand(int command,
java.lang.String args)
Sends an SMTP command to the server, waits for a reply and returns the numerical response code. |
int |
sendCommand(java.lang.String command)
Sends an SMTP command with no arguments to the server, waits for a reply and returns the numerical response code. |
int |
sendCommand(java.lang.String command,
java.lang.String args)
Sends an SMTP command to the server, waits for a reply and returns the numerical response code. |
int |
soml(java.lang.String reversePath)
A convenience method to send the SMTP SOML command to the server, receive the reply, and return the reply code. |
int |
turn()
A convenience method to send the SMTP TURN command to the server, receive the reply, and return the reply code. |
int |
vrfy(java.lang.String user)
A convenience method to send the SMTP VRFY command to the server, receive the reply, and return the reply code. |
Methods inherited from class com.oroinc.net.SocketClient |
connect, connect, connect, connect, connect, connect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_PORT
protected ProtocolCommandSupport _commandSupport_
Constructor Detail |
public SMTP()
DEFAULT_PORT
and initializes internal data structures
for saving SMTP reply information.Method Detail |
protected void _connectAction_() throws java.io.IOException
_connectAction_
in class SocketClient
public void addProtocolCommandListener(ProtocolCommandListener listener)
listener
- The ProtocolCommandListener to add.public void removeProtocolCommandistener(ProtocolCommandListener listener)
listener
- The ProtocolCommandListener to remove.public void disconnect() throws java.io.IOException
disconnect
in class SocketClient
java.io.IOException
- If an error occurs while disconnecting.public int sendCommand(java.lang.String command, java.lang.String args) throws java.io.IOException
command
- The text representation of the SMTP command to send.args
- The arguments to the SMTP command. If this parameter is
set to null, then the command is sent with no argument.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int sendCommand(int command, java.lang.String args) throws java.io.IOException
command
- The SMTPCommand constant corresponding to the SMTP command
to send.args
- The arguments to the SMTP command. If this parameter is
set to null, then the command is sent with no argument.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int sendCommand(java.lang.String command) throws java.io.IOException
command
- The text representation of the SMTP command to send.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int sendCommand(int command) throws java.io.IOException
command
- The SMTPCommand constant corresponding to the SMTP command
to send.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int getReplyCode()
connect
is of type void.
public int getReply() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while receiving the
server reply.public java.lang.String[] getReplyStrings()
public java.lang.String getReplyString()
public int helo(java.lang.String hostname) throws java.io.IOException
hostname
- The hostname of the sender.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int mail(java.lang.String reversePath) throws java.io.IOException
reversePath
- The reverese path.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int rcpt(java.lang.String forwardPath) throws java.io.IOException
forwardPath
- The forward path.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int data() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int send(java.lang.String reversePath) throws java.io.IOException
reversePath
- The reverese path.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int soml(java.lang.String reversePath) throws java.io.IOException
reversePath
- The reverese path.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int saml(java.lang.String reversePath) throws java.io.IOException
reversePath
- The reverese path.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int rset() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int vrfy(java.lang.String user) throws java.io.IOException
user
- The user address to verify.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int expn(java.lang.String name) throws java.io.IOException
name
- The name to expand.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int help() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int help(java.lang.String command) throws java.io.IOException
command
- The command name on which to request help.SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int noop() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int turn() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int quit() throws java.io.IOException
SMTPConnectionClosedException
- If the SMTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send SMTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |