Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.net.SocketClient
org.apache.commons.net.smtp.SMTP
public class SMTP
extends SocketClient
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 | |
static int |
|
private static String | |
private StringBuffer | |
protected ProtocolCommandSupport |
|
(package private) boolean | |
(package private) BufferedReader | |
(package private) int | |
(package private) Vector | |
(package private) String | |
(package private) BufferedWriter |
Fields inherited from class org.apache.commons.net.SocketClient | |
NETASCII_EOL , __DEFAULT_SOCKET_FACTORY , _defaultPort_ , _input_ , _isConnected_ , _output_ , _socketFactory_ , _socket_ , _timeout_ |
Constructor Summary | |
|
Method Summary | |
private void | |
private int |
|
private int |
|
protected void |
|
void |
|
int |
|
void |
|
int |
|
int |
|
int |
|
String |
|
String[] |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
void |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
Methods inherited from class org.apache.commons.net.SocketClient | |
_connectAction_ , connect , connect , connect , connect , connect , connect , disconnect , getDefaultPort , getDefaultTimeout , getLocalAddress , getLocalPort , getRemoteAddress , getRemotePort , getSoLinger , getSoTimeout , getTcpNoDelay , isConnected , setDefaultPort , setDefaultTimeout , setSoLinger , setSoTimeout , setSocketFactory , setTcpNoDelay , verifyRemote |
public static final int DEFAULT_PORT
The default SMTP port (25). **
- Field Value:
- 25
private static final String __DEFAULT_ENCODING
private StringBuffer __commandBuffer
protected ProtocolCommandSupport _commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.
(package private) boolean _newReplyString
(package private) BufferedReader _reader
(package private) int _replyCode
(package private) Vector _replyLines
(package private) String _replyString
(package private) BufferedWriter _writer
public SMTP()
The default SMTP constructor. Sets the default port toDEFAULT_PORT
and initializes internal data structures for saving SMTP reply information.
private void __getReply() throws IOException
private int __sendCommand(String command, String args, boolean includeSpace) throws IOException
private int __sendCommand(int command, String args, boolean includeSpace) throws IOException
protected void _connectAction_() throws IOException
Initiates control connections and gets initial reply. **
- Overrides:
- _connectAction_ in interface SocketClient
public void addProtocolCommandListener(ProtocolCommandListener listener)
Adds a ProtocolCommandListener. Delegates this task to _commandSupport_ .
- Parameters:
listener
- The ProtocolCommandListener to add.
public int data() throws IOException
A convenience method to send the SMTP DATA command to the server, receive the reply, and return the reply code.
- Returns:
- The reply code received from the server.
public void disconnect() throws 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.
- Overrides:
- disconnect in interface SocketClient
public int expn(String name) throws IOException
A convenience method to send the SMTP VRFY command to the server, receive the reply, and return the reply code.
- Parameters:
name
- The name to expand.
- Returns:
- The reply code received from the server.
public int getReply() throws 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 or getReplyStrings . 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.
- Returns:
- The integer value of the reply code of the fetched SMTP reply.
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 sinceconnect
is of type void.
- Returns:
- The integer value of the reply code of the last SMTP reply.
public 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.
- Returns:
- The entire text from the last SMTP response as a String.
public 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.
- Returns:
- The lines of text from the last SMTP response as an array.
public int helo(String hostname) throws IOException
A convenience method to send the SMTP HELO command to the server, receive the reply, and return the reply code.
- Parameters:
hostname
- The hostname of the sender.
- Returns:
- The reply code received from the server.
public int help() throws IOException
A convenience method to send the SMTP HELP command to the server, receive the reply, and return the reply code.
- Returns:
- The reply code received from the server.
public int help(String command) throws IOException
A convenience method to send the SMTP HELP command to the server, receive the reply, and return the reply code.
- Parameters:
command
- The command name on which to request help.
- Returns:
- The reply code received from the server.
public int mail(String reversePath) throws IOException
A convenience method to send the SMTP MAIL command to the server, receive the reply, and return the reply code.
- Parameters:
reversePath
- The reverese path.
- Returns:
- The reply code received from the server.
public int noop() throws IOException
A convenience method to send the SMTP NOOP command to the server, receive the reply, and return the reply code.
- Returns:
- The reply code received from the server.
public int quit() throws IOException
A convenience method to send the SMTP QUIT command to the server, receive the reply, and return the reply code.
- Returns:
- The reply code received from the server.
public int rcpt(String forwardPath) throws IOException
A convenience method to send the SMTP RCPT command to the server, receive the reply, and return the reply code.
- Parameters:
forwardPath
- The forward path.
- Returns:
- The reply code received from the server.
public void removeProtocolCommandistener(ProtocolCommandListener listener)
Removes a ProtocolCommandListener. Delegates this task to _commandSupport_ .
- Parameters:
listener
- The ProtocolCommandListener to remove.
public int rset() throws IOException
A convenience method to send the SMTP RSET command to the server, receive the reply, and return the reply code.
- Returns:
- The reply code received from the server.
public int saml(String reversePath) throws IOException
A convenience method to send the SMTP SAML command to the server, receive the reply, and return the reply code.
- Parameters:
reversePath
- The reverese path.
- Returns:
- The reply code received from the server.
public int send(String reversePath) throws IOException
A convenience method to send the SMTP SEND command to the server, receive the reply, and return the reply code.
- Parameters:
reversePath
- The reverese path.
- Returns:
- The reply code received from the server.
public int sendCommand(String command) throws 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 or getReplyStrings .
- Parameters:
command
- The text representation of the SMTP command to send.
- Returns:
- The integer value of the SMTP reply code returned by the server in response to the command.
public int sendCommand(String command, String args) throws 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 or getReplyStrings .
- Parameters:
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.
- Returns:
- The integer value of the SMTP reply code returned by the server in response to the command.
public int sendCommand(int command) throws 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 or getReplyStrings .
- Parameters:
command
- The SMTPCommand constant corresponding to the SMTP command to send.
- Returns:
- The integer value of the SMTP reply code returned by the server in response to the command.
public int sendCommand(int command, String args) throws 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 or getReplyStrings .
- Parameters:
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.
- Returns:
- The integer value of the SMTP reply code returned by the server in response to the command.
public int soml(String reversePath) throws IOException
A convenience method to send the SMTP SOML command to the server, receive the reply, and return the reply code.
- Parameters:
reversePath
- The reverese path.
- Returns:
- The reply code received from the server.
public int turn() throws IOException
A convenience method to send the SMTP TURN command to the server, receive the reply, and return the reply code.
- Returns:
- The reply code received from the server.
public int vrfy(String user) throws IOException
A convenience method to send the SMTP VRFY command to the server, receive the reply, and return the reply code.
- Parameters:
user
- The user address to verify.
- Returns:
- The reply code received from the server.