|
|||||||||
| Home >> All >> org >> apache >> commons >> net >> [ smtp overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.net.smtp
Class SMTP

java.lang.Objectorg.apache.commons.net.SocketClient
org.apache.commons.net.smtp.SMTP
- Direct Known Subclasses:
- SMTPClient
- public class SMTP
- extends org.apache.commons.net.SocketClient
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 55
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() 55
to properly clean up the system resources used by SMTP. Before
disconnecting, you may check the
last reply code and text with
getReplyCode 55 ,
getReplyString 55 ,
and getReplyStrings 55 .
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 org.apache.commons.net.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.
| Field Summary | |
private java.lang.StringBuffer |
__commandBuffer
|
private static java.lang.String |
__DEFAULT_ENCODING
|
protected org.apache.commons.net.ProtocolCommandSupport |
_commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents. |
(package private) boolean |
_newReplyString
|
(package private) java.io.BufferedReader |
_reader
|
(package private) int |
_replyCode
|
(package private) java.util.Vector |
_replyLines
|
(package private) java.lang.String |
_replyString
|
(package private) java.io.BufferedWriter |
_writer
|
static int |
DEFAULT_PORT
The default SMTP port (25). |
| Fields inherited from class org.apache.commons.net.SocketClient |
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL |
| Constructor Summary | |
SMTP()
The default SMTP constructor. |
|
| Method Summary | |
private void |
__getReply()
|
private int |
__sendCommand(int command,
java.lang.String args,
boolean includeSpace)
|
private int |
__sendCommand(java.lang.String command,
java.lang.String args,
boolean includeSpace)
|
protected void |
_connectAction_()
Initiates control connections and gets initial reply. |
void |
addProtocolCommandListener(org.apache.commons.net.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(org.apache.commons.net.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 org.apache.commons.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 |
DEFAULT_PORT
public static final int DEFAULT_PORT
- The default SMTP port (25).
- See Also:
- Constant Field Values
__DEFAULT_ENCODING
private static final java.lang.String __DEFAULT_ENCODING
- See Also:
- Constant Field Values
__commandBuffer
private java.lang.StringBuffer __commandBuffer
_reader
java.io.BufferedReader _reader
_writer
java.io.BufferedWriter _writer
_replyCode
int _replyCode
_replyLines
java.util.Vector _replyLines
_newReplyString
boolean _newReplyString
_replyString
java.lang.String _replyString
_commandSupport_
protected org.apache.commons.net.ProtocolCommandSupport _commandSupport_
- A ProtocolCommandSupport object used to manage the registering of
ProtocolCommandListeners and te firing of ProtocolCommandEvents.
| Constructor Detail |
SMTP
public SMTP()
- The default SMTP constructor. Sets the default port to
DEFAULT_PORTand initializes internal data structures for saving SMTP reply information.
| Method Detail |
__sendCommand
private int __sendCommand(java.lang.String command, java.lang.String args, boolean includeSpace) throws java.io.IOException
__sendCommand
private int __sendCommand(int command,
java.lang.String args,
boolean includeSpace)
throws java.io.IOException
__getReply
private void __getReply()
throws java.io.IOException
_connectAction_
protected void _connectAction_()
throws java.io.IOException
- Initiates control connections and gets initial reply.
addProtocolCommandListener
public void addProtocolCommandListener(org.apache.commons.net.ProtocolCommandListener listener)
- Adds a ProtocolCommandListener. Delegates this task to
_commandSupport_ 55 .
removeProtocolCommandistener
public void removeProtocolCommandistener(org.apache.commons.net.ProtocolCommandListener listener)
- Removes a ProtocolCommandListener. Delegates this task to
_commandSupport_ 55 .
disconnect
public void disconnect()
throws java.io.IOException
- 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. The reply text and code information from the
last command is voided so that the memory it used may be reclaimed.
sendCommand
public int sendCommand(java.lang.String command, java.lang.String args) throws java.io.IOException
- Sends an SMTP command to the server, waits for a reply and returns the
numerical response code. After invocation, for more detailed
information, the actual reply text can be accessed by calling
getReplyString 55 or
getReplyStrings 55 .
sendCommand
public int sendCommand(int command,
java.lang.String args)
throws java.io.IOException
- Sends an SMTP command to the server, waits for a reply and returns the
numerical response code. After invocation, for more detailed
information, the actual reply text can be accessed by calling
getReplyString 55 or
getReplyStrings 55 .
sendCommand
public int sendCommand(java.lang.String command) throws java.io.IOException
- Sends an SMTP command with no arguments to the server, waits for a
reply and returns the numerical response code. After invocation, for
more detailed information, the actual reply text can be accessed by
calling getReplyString 55 or
getReplyStrings 55 .
sendCommand
public int sendCommand(int command)
throws java.io.IOException
- Sends an SMTP command with no arguments to the server, waits for a
reply and returns the numerical response code. After invocation, for
more detailed information, the actual reply text can be accessed by
calling getReplyString 55 or
getReplyStrings 55 .
getReplyCode
public int getReplyCode()
- Returns the integer value of the reply code of the last SMTP reply.
You will usually only use this method after you connect to the
SMTP server to check that the connection was successful since
connectis of type void.
getReply
public int getReply()
throws java.io.IOException
- Fetches a reply from the SMTP server and returns the integer reply
code. After calling this method, the actual reply text can be accessed
from either calling getReplyString 55 or
getReplyStrings 55 . Only use this
method if you are implementing your own SMTP client or if you need to
fetch a secondary response from the SMTP server.
getReplyStrings
public java.lang.String[] getReplyStrings()
- Returns the lines of text from the last SMTP server response as an array
of strings, one entry per line. The end of line markers of each are
stripped from each line.
getReplyString
public 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.
helo
public int helo(java.lang.String hostname) throws java.io.IOException
- A convenience method to send the SMTP HELO command to the server,
receive the reply, and return the reply code.
public int mail(java.lang.String reversePath) throws java.io.IOException
- A convenience method to send the SMTP MAIL command to the server,
receive the reply, and return the reply code.
rcpt
public int rcpt(java.lang.String forwardPath) throws java.io.IOException
- A convenience method to send the SMTP RCPT command to the server,
receive the reply, and return the reply code.
data
public int data()
throws java.io.IOException
- A convenience method to send the SMTP DATA command to the server,
receive the reply, and return the reply code.
send
public int send(java.lang.String reversePath) throws java.io.IOException
- A convenience method to send the SMTP SEND command to the server,
receive the reply, and return the reply code.
soml
public int soml(java.lang.String reversePath) throws java.io.IOException
- A convenience method to send the SMTP SOML command to the server,
receive the reply, and return the reply code.
saml
public int saml(java.lang.String reversePath) throws java.io.IOException
- A convenience method to send the SMTP SAML command to the server,
receive the reply, and return the reply code.
rset
public int rset()
throws java.io.IOException
- A convenience method to send the SMTP RSET command to the server,
receive the reply, and return the reply code.
vrfy
public int vrfy(java.lang.String user) throws java.io.IOException
- A convenience method to send the SMTP VRFY command to the server,
receive the reply, and return the reply code.
expn
public int expn(java.lang.String name) throws java.io.IOException
- A convenience method to send the SMTP VRFY command to the server,
receive the reply, and return the reply code.
help
public int help()
throws java.io.IOException
- A convenience method to send the SMTP HELP command to the server,
receive the reply, and return the reply code.
help
public int help(java.lang.String command) throws java.io.IOException
- A convenience method to send the SMTP HELP command to the server,
receive the reply, and return the reply code.
noop
public int noop()
throws java.io.IOException
- A convenience method to send the SMTP NOOP command to the server,
receive the reply, and return the reply code.
turn
public int turn()
throws java.io.IOException
- A convenience method to send the SMTP TURN command to the server,
receive the reply, and return the reply code.
quit
public int quit()
throws java.io.IOException
- A convenience method to send the SMTP QUIT command to the server,
receive the reply, and return the reply code.
|
|||||||||
| Home >> All >> org >> apache >> commons >> net >> [ smtp overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC