/** * * @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); }
/** * 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 TLS command execution. * @throws IOException If an I/O error occurs while sending * the command or performing the negotiation. * @return TRUE if the command and negotiation succeeded. */ public boolean execTLS() throws IOException { if (!SMTPReply.isPositiveCompletion(sendCommand("STARTTLS"))) { return false; //throw new SSLException(getReplyString()); } performSSLNegotiation(); return true; }
/*** * Fetches the help information for a given command from the server and * returns the full string. * <p> * @param command The command on which to ask for help. * @return The command help string obtained from the server. null if the * information could not be obtained. * @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 a * command to the server or receiving a reply from the server. ***/ public String listHelp(String command) throws IOException { if (SMTPReply.isPositiveCompletion(help(command))) { return getReplyString(); } return null; }
/*** * Add a recipient for a message using the SMTP RCPT command, specifying * a forward relay path. The sender must be set first before any * recipients may be specified, otherwise the mail server will reject * your commands. * <p> * @param path The forward relay path pointing to the recipient. * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean addRecipient(RelayPath path) throws IOException { return SMTPReply.isPositiveCompletion(rcpt(path.toString())); }
/*** * Set the sender of a message using the SMTP MAIL command, specifying * a reverse relay path. The sender must be set first before any * recipients may be specified, otherwise the mail server will reject * your commands. * <p> * @param path The reverse relay path pointing back to the sender. * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean setSender(RelayPath path) throws IOException { return SMTPReply.isPositiveCompletion(mail(path.toString())); }
/*** * Login to the SMTP server by sending the HELO command with the * given hostname as an argument. Before performing any mail commands, * you must first login. * <p> * @param hostname The hostname with which to greet the SMTP server. * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean login(String hostname) throws IOException { return SMTPReply.isPositiveCompletion(helo(hostname)); }
/*** * Logout of the SMTP server by sending the QUIT command. * <p> * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean logout() throws IOException { return SMTPReply.isPositiveCompletion(quit()); }
/*** * Add a recipient for a message using the SMTP RCPT command, the * recipient's email address. The sender must be set first before any * recipients may be specified, otherwise the mail server will reject * your commands. * <p> * @param address The recipient's email address. * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean addRecipient(String address) throws IOException { return SMTPReply.isPositiveCompletion(rcpt("<" + address + ">")); }
/*** * Set the sender of a message using the SMTP MAIL command, specifying * the sender's email address. The sender must be set first before any * recipients may be specified, otherwise the mail server will reject * your commands. * <p> * @param address The sender's email address. * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean setSender(String address) throws IOException { return SMTPReply.isPositiveCompletion(mail("<" + address + ">")); }
/*** * Sends a NOOP command to the SMTP server. This is useful for preventing * server timeouts. * <p> * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean sendNoOp() throws IOException { return SMTPReply.isPositiveCompletion(noop()); }
/*** * Aborts the current mail transaction, resetting all server stored * sender, recipient, and mail data, cleaing all buffers and tables. * <p> * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean reset() throws IOException { return SMTPReply.isPositiveCompletion(rset()); }
/*** * Login to the ESMTP server by sending the EHLO command with the * given hostname as an argument. Before performing any mail commands, * you must first login. * <p> * @param hostname The hostname with which to greet the SMTP server. * @return True if successfully completed, false if not. * @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 a * command to the server or receiving a reply from the server. ***/ public boolean elogin(String hostname) throws IOException { return SMTPReply.isPositiveCompletion(ehlo(hostname)); }
/*** * 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); }
/** * Because there are so many connect() methods, * the _connectAction_() method is provided as a means of performing * some action immediately after establishing a connection, * rather than reimplementing all of the connect() methods. * @throws IOException If it is thrown by _connectAction_(). * @see org.apache.commons.net.SocketClient#_connectAction_() */ @Override protected void _connectAction_() throws IOException { // Implicit mode. if (isImplicit) { performSSLNegotiation(); } super._connectAction_(); // Explicit mode - don't do anything. The user calls execTLS() }
/** * Performs a lazy init of the SSL context. * @throws IOException When could not initialize the SSL context. */ private void initSSLContext() throws IOException { if (context == null) { context = SSLContextUtils.createSSLContext(protocol, getKeyManager(), getTrustManager()); } }
/*** * 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); }
/*** * 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); }
/*** * 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 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. * @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 expn(String name) throws IOException { return sendCommand(SMTPCommand.EXPN, name); }