Package org.apache.commons.net.smtp
Class AuthenticatingSMTPClient
java.lang.Object
org.apache.commons.net.SocketClient
org.apache.commons.net.smtp.SMTP
org.apache.commons.net.smtp.SMTPClient
org.apache.commons.net.smtp.SMTPSClient
org.apache.commons.net.smtp.AuthenticatingSMTPClient
An SMTP Client class with authentication support (RFC4954).
- Since:
- 3.0
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumThe enumeration of currently-supported authentication methods.
- 
Field SummaryFields inherited from class org.apache.commons.net.smtp.SMTP_commandSupport_, DEFAULT_PORT, encodingFields inherited from class org.apache.commons.net.SocketClient_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress
- 
Constructor SummaryConstructorsConstructorDescriptionThe default AuthenticatingSMTPClient constructor.AuthenticatingSMTPClient(boolean implicit, SSLContext ctx) Overloaded constructor that takes the implicit argument, and usingSMTPSClient.DEFAULT_PROTOCOLi.e.AuthenticatingSMTPClient(String protocol) Overloaded constructor that takes a protocol specificationAuthenticatingSMTPClient(String proto, boolean implicit) Overloaded constructor that takes a protocol specification and the implicit argumentAuthenticatingSMTPClient(String proto, boolean implicit, String encoding) Overloaded constructor that takes the protocol specification, the implicit argument and encodingAuthenticatingSMTPClient(String protocol, String encoding) Overloaded constructor that takes a protocol specification and encoding
- 
Method SummaryModifier and TypeMethodDescriptionbooleanauth(AuthenticatingSMTPClient.AUTH_METHOD method, String user, String password) Authenticate to the SMTP server by sending the AUTH command with the selected mechanism, using the given user and the given password.intA convenience method to send the ESMTP EHLO command to the server, receive the reply, and return the reply code.booleanelogin()Login to the ESMTP server by sending the EHLO command with the client hostname as an argument.booleanLogin to the ESMTP server by sending the EHLO command with the given hostname as an argument.int[]Returns the integer values of the enhanced reply code of the last SMTP reply.Methods inherited from class org.apache.commons.net.smtp.SMTPSClient_connectAction_, execTLS, getEnabledCipherSuites, getEnabledProtocols, getHostnameVerifier, getKeyManager, getTrustManager, isEndpointCheckingEnabled, setEnabledCipherSuites, setEnabledProtocols, setEndpointCheckingEnabled, setHostnameVerifier, setKeyManager, setTrustManagerMethods inherited from class org.apache.commons.net.smtp.SMTPClientaddRecipient, addRecipient, completePendingCommand, listHelp, listHelp, login, login, logout, reset, sendMessageData, sendNoOp, sendShortMessageData, sendSimpleMessage, sendSimpleMessage, setSender, setSender, verifyMethods inherited from class org.apache.commons.net.smtp.SMTPdata, disconnect, expn, getCommandSupport, getReply, getReplyCode, getReplyString, getReplyStrings, helo, help, help, mail, noop, quit, rcpt, removeProtocolCommandistener, rset, saml, send, sendCommand, sendCommand, sendCommand, sendCommand, soml, turn, vrfyMethods inherited from class org.apache.commons.net.SocketClientaddProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemoteInetSocketAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
- 
Constructor Details- 
AuthenticatingSMTPClientpublic AuthenticatingSMTPClient()The default AuthenticatingSMTPClient constructor. Creates a new Authenticating SMTP Client.
- 
AuthenticatingSMTPClientOverloaded constructor that takes the implicit argument, and usingSMTPSClient.DEFAULT_PROTOCOLi.e. TLS- Parameters:
- implicit- The security mode,- truefor implicit,- falsefor explicit
- ctx- A pre-configured SSL Context.
- Since:
- 3.3
 
- 
AuthenticatingSMTPClientOverloaded constructor that takes a protocol specification- Parameters:
- protocol- The protocol to use
 
- 
AuthenticatingSMTPClientOverloaded constructor that takes a protocol specification and the implicit argument- Parameters:
- proto- the protocol.
- implicit- The security mode,- truefor implicit,- falsefor explicit
- Since:
- 3.3
 
- 
AuthenticatingSMTPClientOverloaded constructor that takes the protocol specification, the implicit argument and encoding- Parameters:
- proto- the protocol.
- implicit- The security mode,- truefor implicit,- falsefor explicit
- encoding- the encoding
- Since:
- 3.3
 
- 
AuthenticatingSMTPClientOverloaded constructor that takes a protocol specification and encoding- Parameters:
- protocol- The protocol to use
- encoding- The encoding to use
- Since:
- 3.3
 
 
- 
- 
Method Details- 
authpublic boolean auth(AuthenticatingSMTPClient.AUTH_METHOD method, String user, String password) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException Authenticate to the SMTP server by sending the AUTH command with the selected mechanism, using the given user and the given password.- Parameters:
- method- the method to use, one of the- AuthenticatingSMTPClient.AUTH_METHODenum values
- user- the user name. If the method is XOAUTH/XOAUTH2, then this is used as the plain text oauth protocol parameter string which is Base64-encoded for transmission.
- password- the password for the username. Ignored for XOAUTH/XOAUTH2.
- Returns:
- 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.
- IOException- If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
- NoSuchAlgorithmException- If the CRAM hash algorithm cannot be instantiated by the Java runtime system.
- InvalidKeyException- If the CRAM hash algorithm failed to use the given password.
- InvalidKeySpecException- If the CRAM hash algorithm failed to use the given password.
 
- 
ehloA convenience method to send the ESMTP EHLO 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.
- 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.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
eloginLogin to the ESMTP server by sending the EHLO command with the client hostname as an argument. Before performing any mail commands, you must first login.- Returns:
- 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.
- IOException- If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
 
- 
eloginLogin 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.- Parameters:
- hostname- The hostname with which to greet the SMTP server.
- Returns:
- 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.
- IOException- If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
 
- 
getEnhancedReplyCodeReturns the integer values of the enhanced reply code of the last SMTP reply.- Returns:
- The integer values of the enhanced reply code of the last SMTP reply. First digit is in the first array element.
 
 
-