/*** * 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 {@link #getReplyString getReplyString } or * {@link #getReplyStrings 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. * <p> * @return The integer value of the reply code of the fetched SMTP reply. * @throws 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. * @throws IOException If an I/O error occurs while receiving the * server reply. ***/ public int getReply() throws IOException { __getReply(); return _replyCode; }
/*** * A convenience method to send the SMTP RCPT command to the server, * receive the reply, and return the reply code. * <p> * @param forwardPath The forward path. * @return The reply code received from the server. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int rcpt(String forwardPath) throws IOException { return __sendCommand(SMTPCommand.RCPT, forwardPath, false); }
/*** * A convenience method to send the SMTP DATA command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int data() throws IOException { return sendCommand(SMTPCommand.DATA); }
/** * Send a command to the server. May also be used to send text data. * * @param command the command to send (as a plain String) * @param args the command arguments, may be {@code null} * @param includeSpace if {@code true}, add a space between the command and its arguments * @return the reply code * @throws IOException */ private int __sendCommand(String command, String args, boolean includeSpace) throws IOException { StringBuilder __commandBuffer = new StringBuilder(); __commandBuffer.append(command); if (args != null) { if (includeSpace) { __commandBuffer.append(' '); } __commandBuffer.append(args); } __commandBuffer.append(SocketClient.NETASCII_EOL); String message; _writer.write(message = __commandBuffer.toString()); _writer.flush(); fireCommandSent(command, message); __getReply(); return _replyCode; }
/** * Overloaded constructor where the user may specify a default encoding. * @param encoding the encoing to use * @since 2.0 */ public SMTP(String encoding) { setDefaultPort(DEFAULT_PORT); _replyLines = new ArrayList<String>(); _newReplyString = false; _replyString = null; _commandSupport_ = new ProtocolCommandSupport(this); this.encoding = encoding; }
fireReplyReceived(_replyCode, getReplyString());
_commandSupport_.fireReplyReceived(_replyCode, getReplyString());
/** * Removes a ProtocolCommandListener. * * Delegates this incorrectly named method - removeProtocolCommandistener (note the missing "L")- to * the correct method {@link SocketClient#removeProtocolCommandListener} * @param listener The ProtocolCommandListener to remove */ public void removeProtocolCommandistener(org.apache.commons.net.ProtocolCommandListener listener){ removeProtocolCommandListener(listener); }
/*** * The default SMTP constructor. Sets the default port to * <code>DEFAULT_PORT</code> and initializes internal data structures * for saving SMTP reply information. ***/ public SMTP() { setDefaultPort(DEFAULT_PORT); __commandBuffer = new StringBuffer(); _replyLines = new ArrayList<String>(); _newReplyString = false; _replyString = null; _commandSupport_ = new ProtocolCommandSupport(this); }
_commandSupport_.fireReplyReceived(_replyCode, getReplyString());
/*** * A convenience method to send the SMTP TURN command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int turn() throws IOException { return sendCommand(SMTPCommand.TURN); }
/*** * A convenience method to send the SMTP MAIL command to the server, * receive the reply, and return the reply code. * <p> * @param reversePath The reverese path. * @return The reply code received from the server. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int mail(String reversePath) throws IOException { return __sendCommand(SMTPCommand.MAIL, reversePath, false); }
/*** Initiates control connections and gets initial reply. ***/ @Override protected void _connectAction_() throws IOException { super._connectAction_(); _reader = new CRLFLineReader(new InputStreamReader(_input_, encoding)); _writer = new BufferedWriter(new OutputStreamWriter(_output_, encoding)); __getReply(); }
/*** * The default SMTP constructor. Sets the default port to * <code>DEFAULT_PORT</code> and initializes internal data structures * for saving SMTP reply information. ***/ public SMTP() { setDefaultPort(DEFAULT_PORT); __commandBuffer = new StringBuffer(); _replyLines = new Vector(); _newReplyString = false; _replyString = null; _commandSupport_ = new ProtocolCommandSupport(this); }
/*** * A convenience method to send the SMTP HELP command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int help() throws IOException { return sendCommand(SMTPCommand.HELP); }
/*** * 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 * {@link #getReplyString getReplyString } or * {@link #getReplyStrings getReplyStrings }. * <p> * @param command The text representation of the SMTP command to send. * @param args The arguments to the SMTP command. If this parameter is * set to null, then the command is sent with no argument. * @return The integer value of the SMTP reply code returned by the server * in response to the command. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int sendCommand(String command, String args) throws IOException { return __sendCommand(command, args, true); }
/*** * 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 {@link #getReplyString getReplyString } or * {@link #getReplyStrings 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. * <p> * @return The integer value of the reply code of the fetched SMTP reply. * @exception 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. * @exception IOException If an I/O error occurs while receiving the * server reply. ***/ public int getReply() throws IOException { __getReply(); return _replyCode; }
/*** * A convenience method to send the SMTP QUIT command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @throws 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. * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int quit() throws IOException { return sendCommand(SMTPCommand.QUIT); }
/** * * @param command the command to send (as an int defined in {@link SMPTCommand}) * @param args the command arguments, may be {@code null} * @param includeSpace if {@code true}, add a space between the command and its arguments * @return the reply code * @throws IOException */ private int __sendCommand(int command, String args, boolean includeSpace) throws IOException { return __sendCommand(SMTPCommand.getCommand(command), args, includeSpace); }
/*** * 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 {@link #getReplyString getReplyString } or * {@link #getReplyStrings 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. * <p> * @return The integer value of the reply code of the fetched SMTP reply. * @exception 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. * @exception IOException If an I/O error occurs while receiving the * server reply. ***/ public int getReply() throws IOException { __getReply(); return _replyCode; }