smtp.java

来自「apache推出的net包」· Java 代码 · 共 760 行 · 第 1/2 页

JAVA
760
字号
     * 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     * <code> connect </code> is of type void.     * <p>     * @return The integer value of the reply code of the last SMTP reply.     ***/    public int getReplyCode()    {        return _replyCode;    }    /***     * 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;    }    /***     * 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.     * <p>     * @return The lines of text from the last SMTP response as an array.     ***/    public String[] getReplyStrings()    {        String[] lines;        lines = new String[_replyLines.size()];        _replyLines.copyInto(lines);        return lines;    }    /***     * Returns the entire text of the last SMTP server response exactly     * as it was received, including all end of line markers in NETASCII     * format.     * <p>     * @return The entire text from the last SMTP response as a String.     ***/    public String getReplyString()    {        Enumeration en;        StringBuffer buffer;        if (!_newReplyString)            return _replyString;        buffer = new StringBuffer(256);        en = _replyLines.elements();        while (en.hasMoreElements())        {            buffer.append((String)en.nextElement());            buffer.append(SocketClient.NETASCII_EOL);        }        _newReplyString = false;        return (_replyString = buffer.toString());    }    /***     * A convenience method to send the SMTP HELO command to the server,     * receive the reply, and return the reply code.     * <p>     * @param hostname The hostname of the sender.     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int helo(String hostname) throws IOException    {        return sendCommand(SMTPCommand.HELO, hostname);    }    /***     * 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.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int mail(String reversePath) throws IOException    {        return __sendCommand(SMTPCommand.MAIL, reversePath, false);    }    /***     * 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.     * @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 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.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int data() throws IOException    {        return sendCommand(SMTPCommand.DATA);    }    /***     * A convenience method to send the SMTP SEND 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.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int send(String reversePath) throws IOException    {        return sendCommand(SMTPCommand.SEND, reversePath);    }    /***     * A convenience method to send the SMTP SOML 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.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int soml(String reversePath) throws IOException    {        return sendCommand(SMTPCommand.SOML, reversePath);    }    /***     * A convenience method to send the SMTP SAML 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.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int saml(String reversePath) throws IOException    {        return sendCommand(SMTPCommand.SAML, reversePath);    }    /***     * A convenience method to send the SMTP RSET command to the server,     * receive the reply, and return the reply code.     * <p>     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int rset() throws IOException    {        return sendCommand(SMTPCommand.RSET);    }    /***     * A convenience method to send the SMTP VRFY command to the server,     * receive the reply, and return the reply code.     * <p>     * @param user The user address to verify.     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int vrfy(String user) throws IOException    {        return sendCommand(SMTPCommand.VRFY, user);    }    /***     * A convenience method to send the SMTP VRFY command to the server,     * receive the reply, and return the reply code.     * <p>     * @param name The name to expand.     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int expn(String name) throws IOException    {        return sendCommand(SMTPCommand.EXPN, name);    }    /***     * 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.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int help() throws IOException    {        return sendCommand(SMTPCommand.HELP);    }    /***     * A convenience method to send the SMTP HELP command to the server,     * receive the reply, and return the reply code.     * <p>     * @param command  The command name on which to request help.     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int help(String command) throws IOException    {        return sendCommand(SMTPCommand.HELP, command);    }    /***     * A convenience method to send the SMTP NOOP command to the server,     * receive the reply, and return the reply code.     * <p>     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int noop() throws IOException    {        return sendCommand(SMTPCommand.NOOP);    }    /***     * 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.     * @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 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 QUIT command to the server,     * receive the reply, and return the reply code.     * <p>     * @return The reply code received from the server.     * @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 either sending the     *      command or receiving the server reply.     ***/    public int quit() throws IOException    {        return sendCommand(SMTPCommand.QUIT);    }}/* Emacs configuration * Local variables:        ** * mode:             java  ** * c-basic-offset:   4     ** * indent-tabs-mode: nil   ** * End:                    ** */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?