Package org.apache.commons.net.smtp
Class SMTPSClient
- 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
-
- Direct Known Subclasses:
AuthenticatingSMTPClient
public class SMTPSClient extends SMTPClient
SMTP over SSL processing. Copied from FTPSClient.java and modified to suit SMTP. If implicit mode is selected (NOT the default), SSL/TLS negotiation starts right after the connection has been established. In explicit mode (the default), SSL/TLS negotiation starts when the user calls execTLS() and the server accepts the command. Implicit usage:SMTPSClient c = new SMTPSClient(true); c.connect("127.0.0.1", 465);Explicit usage:SMTPSClient c = new SMTPSClient(); c.connect("127.0.0.1", 25); if (c.execTLS()) { // Rest of the commands here }Warning: the hostname is not verified against the certificate by default, usesetHostnameVerifier(HostnameVerifier)orsetEndpointCheckingEnabled(boolean)(on Java 1.7+) to enable verification.- Since:
- 3.0
-
-
Field Summary
-
Fields inherited from class org.apache.commons.net.smtp.SMTP
_commandSupport_, DEFAULT_PORT, encoding
-
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress
-
-
Constructor Summary
Constructors Constructor Description SMTPSClient()Constructor for SMTPSClient, usingDEFAULT_PROTOCOLi.e.SMTPSClient(boolean implicit)Constructor for SMTPSClient, usingDEFAULT_PROTOCOLi.e.SMTPSClient(boolean implicit, javax.net.ssl.SSLContext ctx)Constructor for SMTPSClient, usingDEFAULT_PROTOCOLi.e.SMTPSClient(java.lang.String proto)Constructor for SMTPSClient, using explicit security mode.SMTPSClient(java.lang.String proto, boolean implicit)Constructor for SMTPSClient.SMTPSClient(java.lang.String proto, boolean implicit, java.lang.String encoding)Constructor for SMTPSClient.SMTPSClient(javax.net.ssl.SSLContext context)Constructor for SMTPSClient.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_connectAction_()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 the connect() methods.booleanexecTLS()The TLS command execution.java.lang.String[]getEnabledCipherSuites()Gets the names of the cipher suites which could be enabled for use on this connection.java.lang.String[]getEnabledProtocols()Gets the names of the protocol versions which are currently enabled for use on this connection.javax.net.ssl.HostnameVerifiergetHostnameVerifier()Gets the currently configuredHostnameVerifier.javax.net.ssl.KeyManagergetKeyManager()Gets theKeyManagerinstance.javax.net.ssl.TrustManagergetTrustManager()Gets the currently configuredTrustManager.booleanisEndpointCheckingEnabled()Tests whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled.voidsetEnabledCipherSuites(java.lang.String[] cipherSuites)Sets which particular cipher suites are enabled for use on this connection.voidsetEnabledProtocols(java.lang.String[] protocolVersions)Sets which particular protocol versions are enabled for use on this connection.voidsetEndpointCheckingEnabled(boolean enable)Sets automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+.voidsetHostnameVerifier(javax.net.ssl.HostnameVerifier newHostnameVerifier)Sets to override the defaultHostnameVerifierto use.voidsetKeyManager(javax.net.ssl.KeyManager newKeyManager)Sets aKeyManagerto use.voidsetTrustManager(javax.net.ssl.TrustManager newTrustManager)Override the defaultTrustManagerto use.-
Methods inherited from class org.apache.commons.net.smtp.SMTPClient
addRecipient, addRecipient, completePendingCommand, listHelp, listHelp, login, login, logout, reset, sendMessageData, sendNoOp, sendShortMessageData, sendSimpleMessage, sendSimpleMessage, setSender, setSender, verify
-
Methods inherited from class org.apache.commons.net.smtp.SMTP
data, disconnect, expn, getCommandSupport, getReply, getReplyCode, getReplyString, getReplyStrings, helo, help, help, mail, noop, quit, rcpt, removeProtocolCommandistener, rset, saml, send, sendCommand, sendCommand, sendCommand, sendCommand, soml, turn, vrfy
-
Methods inherited from class org.apache.commons.net.SocketClient
addProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getConnectTimeout, getDefaultPort, getDefaultTimeout, getHostAddress, getHostAddress, 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 Detail
-
SMTPSClient
public SMTPSClient()
Constructor for SMTPSClient, usingDEFAULT_PROTOCOLi.e. TLS Sets security mode to explicit (isImplicit = false).
-
SMTPSClient
public SMTPSClient(boolean implicit)
Constructor for SMTPSClient, usingDEFAULT_PROTOCOLi.e. TLS- Parameters:
implicit- The security mode,truefor implicit,falsefor explicit
-
SMTPSClient
public SMTPSClient(boolean implicit, javax.net.ssl.SSLContext ctx)
Constructor for SMTPSClient, usingDEFAULT_PROTOCOLi.e. TLS- Parameters:
implicit- The security mode,truefor implicit,falsefor explicitctx- A pre-configured SSL Context.
-
SMTPSClient
public SMTPSClient(javax.net.ssl.SSLContext context)
Constructor for SMTPSClient.- Parameters:
context- A pre-configured SSL Context.- See Also:
SMTPSClient(boolean, SSLContext)
-
SMTPSClient
public SMTPSClient(java.lang.String proto)
Constructor for SMTPSClient, using explicit security mode.- Parameters:
proto- the protocol.
-
SMTPSClient
public SMTPSClient(java.lang.String proto, boolean implicit)
Constructor for SMTPSClient.- Parameters:
proto- the protocol.implicit- The security mode,truefor implicit,falsefor explicit
-
SMTPSClient
public SMTPSClient(java.lang.String proto, boolean implicit, java.lang.String encoding)
Constructor for SMTPSClient.- Parameters:
proto- the protocol.implicit- The security mode,truefor implicit,falsefor explicitencoding- the encoding- Since:
- 3.3
-
-
Method Detail
-
_connectAction_
protected void _connectAction_() throws java.io.IOException
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 the connect() methods.- Overrides:
_connectAction_in classSMTP- Throws:
java.io.IOException- If it is thrown by _connectAction_().- See Also:
SocketClient._connectAction_()
-
execTLS
public boolean execTLS() throws java.io.IOException
The TLS command execution.- Returns:
- TRUE if the command and negotiation succeeded.
- Throws:
java.io.IOException- If an I/O error occurs while sending the command or performing the negotiation.
-
getEnabledCipherSuites
public java.lang.String[] getEnabledCipherSuites()
Gets the names of the cipher suites which could be enabled for use on this connection. When the underlyingSocketis not anSSLSocketinstance, returns null.- Returns:
- An array of cipher suite names, or
null.
-
getEnabledProtocols
public java.lang.String[] getEnabledProtocols()
Gets the names of the protocol versions which are currently enabled for use on this connection. When the underlyingSocketis not anSSLSocketinstance, returns null.- Returns:
- An array of protocols, or
null.
-
getHostnameVerifier
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
Gets the currently configuredHostnameVerifier.- Returns:
- A HostnameVerifier instance.
- Since:
- 3.4
-
getKeyManager
public javax.net.ssl.KeyManager getKeyManager()
Gets theKeyManagerinstance.- Returns:
- The current
KeyManagerinstance.
-
getTrustManager
public javax.net.ssl.TrustManager getTrustManager()
Gets the currently configuredTrustManager.- Returns:
- A TrustManager instance.
-
isEndpointCheckingEnabled
public boolean isEndpointCheckingEnabled()
Tests whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled. The default behavior is for this to be disabled.- Returns:
- True if enabled, false if not.
- Since:
- 3.4
-
setEnabledCipherSuites
public void setEnabledCipherSuites(java.lang.String[] cipherSuites)
Sets which particular cipher suites are enabled for use on this connection. Called before server negotiation.- Parameters:
cipherSuites- The cipher suites.
-
setEnabledProtocols
public void setEnabledProtocols(java.lang.String[] protocolVersions)
Sets which particular protocol versions are enabled for use on this connection. I perform setting before a server negotiation.- Parameters:
protocolVersions- The protocol versions.
-
setEndpointCheckingEnabled
public void setEndpointCheckingEnabled(boolean enable)
Sets automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+. The default behavior is for this to be disabled.- Parameters:
enable- Enable automatic endpoint identification checking using the HTTPS algorithm on Java 1.7+.- Since:
- 3.4
-
setHostnameVerifier
public void setHostnameVerifier(javax.net.ssl.HostnameVerifier newHostnameVerifier)
Sets to override the defaultHostnameVerifierto use.- Parameters:
newHostnameVerifier- The HostnameVerifier implementation to set ornullto disable.- Since:
- 3.4
-
setKeyManager
public void setKeyManager(javax.net.ssl.KeyManager newKeyManager)
Sets aKeyManagerto use.- Parameters:
newKeyManager- The KeyManager implementation to set.- See Also:
KeyManagerUtils
-
setTrustManager
public void setTrustManager(javax.net.ssl.TrustManager newTrustManager)
Override the defaultTrustManagerto use.- Parameters:
newTrustManager- The TrustManager implementation to set.- See Also:
TrustManagerUtils
-
-