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
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, use
setHostnameVerifier(HostnameVerifier)
or setEndpointCheckingEnabled(boolean)
(on Java 1.7+) to enable verification.- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SSLContext
The context object.private static final String
Default secure socket protocol name, like TLSprivate HostnameVerifier
TheHostnameVerifier
to use post-TLS, default null (i.e.private final boolean
The security mode.private KeyManager
TheKeyManager
, default null (i.e.private final String
The secure socket protocol to be used, like SSL/TLS.private String[]
The protocol versions.private String[]
The cipher suites.private boolean
Use Java 1.7+ HTTPS Endpoint Identification Algorithim.private TrustManager
TheTrustManager
implementation, default null (i.e.Fields inherited from class org.apache.commons.net.smtp.SMTP
_commandSupport_, DEFAULT_PORT, encoding, reader, writer
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for SMTPSClient, usingDEFAULT_PROTOCOL
i.e.SMTPSClient
(boolean implicit) Constructor for SMTPSClient, usingDEFAULT_PROTOCOL
i.e.SMTPSClient
(boolean implicit, SSLContext ctx) Constructor for SMTPSClient, usingDEFAULT_PROTOCOL
i.e.SMTPSClient
(String proto) Constructor for SMTPSClient, using explicit security mode.SMTPSClient
(String proto, boolean implicit) Constructor for SMTPSClient.SMTPSClient
(String proto, boolean implicit, String encoding) Constructor for SMTPSClient.SMTPSClient
(SSLContext context) Constructor for SMTPSClient. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
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.boolean
execTLS()
The TLS command execution.String[]
Returns the names of the cipher suites which could be enabled for use on this connection.String[]
Returns the names of the protocol versions which are currently enabled for use on this connection.Get the currently configuredHostnameVerifier
.Get theKeyManager
instance.Get the currently configuredTrustManager
.private void
Performs a lazy init of the SSL context.boolean
Return whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled.private void
SSL/TLS negotiation.void
setEnabledCipherSuites
(String[] cipherSuites) Controls which particular cipher suites are enabled for use on this connection.void
setEnabledProtocols
(String[] protocolVersions) Controls which particular protocol versions are enabled for use on this connection.void
setEndpointCheckingEnabled
(boolean enable) Automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+.void
setHostnameVerifier
(HostnameVerifier newHostnameVerifier) Override the defaultHostnameVerifier
to use.void
setKeyManager
(KeyManager newKeyManager) Set aKeyManager
to use.void
setTrustManager
(TrustManager newTrustManager) Override the defaultTrustManager
to 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, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
-
Field Details
-
DEFAULT_PROTOCOL
Default secure socket protocol name, like TLS- See Also:
-
isImplicit
private final boolean isImplicitThe security mode. True - Implicit Mode / False - Explicit Mode. -
protocol
The secure socket protocol to be used, like SSL/TLS. -
context
The context object. -
suites
The cipher suites. SSLSockets have a default set of these anyway, so no initialization required. -
protocols
The protocol versions. -
trustManager
TheTrustManager
implementation, default null (i.e. use system managers). -
keyManager
TheKeyManager
, default null (i.e. use system managers). -
hostnameVerifier
TheHostnameVerifier
to use post-TLS, default null (i.e. no verification). -
tlsEndpointChecking
private boolean tlsEndpointCheckingUse Java 1.7+ HTTPS Endpoint Identification Algorithim.
-
-
Constructor Details
-
SMTPSClient
public SMTPSClient()Constructor for SMTPSClient, usingDEFAULT_PROTOCOL
i.e. TLS Sets security mode to explicit (isImplicit = false). -
SMTPSClient
public SMTPSClient(boolean implicit) Constructor for SMTPSClient, usingDEFAULT_PROTOCOL
i.e. TLS- Parameters:
implicit
- The security mode,true
for implicit,false
for explicit
-
SMTPSClient
Constructor for SMTPSClient, using explicit security mode.- Parameters:
proto
- the protocol.
-
SMTPSClient
Constructor for SMTPSClient.- Parameters:
proto
- the protocol.implicit
- The security mode,true
for implicit,false
for explicit
-
SMTPSClient
Constructor for SMTPSClient.- Parameters:
proto
- the protocol.implicit
- The security mode,true
for implicit,false
for explicitencoding
- the encoding- Since:
- 3.3
-
SMTPSClient
Constructor for SMTPSClient, usingDEFAULT_PROTOCOL
i.e. TLS- Parameters:
implicit
- The security mode,true
for implicit,false
for explicitctx
- A pre-configured SSL Context.
-
SMTPSClient
Constructor for SMTPSClient.- Parameters:
context
- A pre-configured SSL Context.- See Also:
-
-
Method Details
-
_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 of the connect() methods.- Overrides:
_connectAction_
in classSMTP
- Throws:
IOException
- If it is thrown by _connectAction_().- See Also:
-
initSSLContext
Performs a lazy init of the SSL context.- Throws:
IOException
- When could not initialize the SSL context.
-
performSSLNegotiation
SSL/TLS negotiation. Acquires an SSL socket of a connection and carries out handshake processing.- Throws:
IOException
- If server negotiation fails.
-
getKeyManager
Get theKeyManager
instance.- Returns:
- The current
KeyManager
instance.
-
setKeyManager
Set aKeyManager
to use.- Parameters:
newKeyManager
- The KeyManager implementation to set.- See Also:
-
setEnabledCipherSuites
Controls which particular cipher suites are enabled for use on this connection. Called before server negotiation.- Parameters:
cipherSuites
- The cipher suites.
-
getEnabledCipherSuites
Returns the names of the cipher suites which could be enabled for use on this connection. When the underlyingSocket
is not anSSLSocket
instance, returns null.- Returns:
- An array of cipher suite names, or
null
.
-
setEnabledProtocols
Controls which particular protocol versions are enabled for use on this connection. I perform setting before a server negotiation.- Parameters:
protocolVersions
- The protocol versions.
-
getEnabledProtocols
Returns the names of the protocol versions which are currently enabled for use on this connection. When the underlyingSocket
is not anSSLSocket
instance, returns null.- Returns:
- An array of protocols, or
null
.
-
execTLS
The TLS command execution.- Returns:
- TRUE if the command and negotiation succeeded.
- Throws:
IOException
- If an I/O error occurs while sending the command or performing the negotiation.
-
getTrustManager
Get the currently configuredTrustManager
.- Returns:
- A TrustManager instance.
-
setTrustManager
Override the defaultTrustManager
to use.- Parameters:
newTrustManager
- The TrustManager implementation to set.- See Also:
-
getHostnameVerifier
Get the currently configuredHostnameVerifier
.- Returns:
- A HostnameVerifier instance.
- Since:
- 3.4
-
setHostnameVerifier
Override the defaultHostnameVerifier
to use.- Parameters:
newHostnameVerifier
- The HostnameVerifier implementation to set ornull
to disable.- Since:
- 3.4
-
isEndpointCheckingEnabled
public boolean isEndpointCheckingEnabled()Return 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
-
setEndpointCheckingEnabled
public void setEndpointCheckingEnabled(boolean enable) 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
-