Class 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, use setHostnameVerifier(HostnameVerifier) or setEndpointCheckingEnabled(boolean) (on Java 1.7+) to enable verification.
Since:
3.0
  • Constructor Details Link icon

    • SMTPSClient Link icon

      public SMTPSClient()
      Constructor for SMTPSClient, using DEFAULT_PROTOCOL i.e. TLS Sets security mode to explicit (isImplicit = false).
    • SMTPSClient Link icon

      public SMTPSClient(boolean implicit)
      Constructor for SMTPSClient, using DEFAULT_PROTOCOL i.e. TLS
      Parameters:
      implicit - The security mode, true for implicit, false for explicit
    • SMTPSClient Link icon

      public SMTPSClient(boolean implicit, SSLContext ctx)
      Constructor for SMTPSClient, using DEFAULT_PROTOCOL i.e. TLS
      Parameters:
      implicit - The security mode, true for implicit, false for explicit
      ctx - A pre-configured SSL Context.
    • SMTPSClient Link icon

      public SMTPSClient(SSLContext context)
      Constructor for SMTPSClient.
      Parameters:
      context - A pre-configured SSL Context.
      See Also:
    • SMTPSClient Link icon

      public SMTPSClient(String proto)
      Constructor for SMTPSClient, using explicit security mode.
      Parameters:
      proto - the protocol.
    • SMTPSClient Link icon

      public SMTPSClient(String proto, boolean implicit)
      Constructor for SMTPSClient.
      Parameters:
      proto - the protocol.
      implicit - The security mode, true for implicit, false for explicit
    • SMTPSClient Link icon

      public SMTPSClient(String proto, boolean implicit, String encoding)
      Constructor for SMTPSClient.
      Parameters:
      proto - the protocol.
      implicit - The security mode, true for implicit, false for explicit
      encoding - the encoding
      Since:
      3.3
  • Method Details Link icon

    • _connectAction_ Link icon

      protected void _connectAction_() throws 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 class SMTP
      Throws:
      IOException - If it is thrown by _connectAction_().
      See Also:
    • execTLS Link icon

      public boolean execTLS() throws IOException
      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.
    • getEnabledCipherSuites Link icon

      Returns the names of the cipher suites which could be enabled for use on this connection. When the underlying Socket is not an SSLSocket instance, returns null.
      Returns:
      An array of cipher suite names, or null.
    • getEnabledProtocols Link icon

      Returns the names of the protocol versions which are currently enabled for use on this connection. When the underlying Socket is not an SSLSocket instance, returns null.
      Returns:
      An array of protocols, or null.
    • getHostnameVerifier Link icon

      Gets the currently configured HostnameVerifier.
      Returns:
      A HostnameVerifier instance.
      Since:
      3.4
    • getKeyManager Link icon

      Gets the KeyManager instance.
      Returns:
      The current KeyManager instance.
    • getTrustManager Link icon

      Gets the currently configured TrustManager.
      Returns:
      A TrustManager instance.
    • isEndpointCheckingEnabled Link icon

      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
    • setEnabledCipherSuites Link icon

      public void setEnabledCipherSuites(String[] cipherSuites)
      Controls which particular cipher suites are enabled for use on this connection. Called before server negotiation.
      Parameters:
      cipherSuites - The cipher suites.
    • setEnabledProtocols Link icon

      public void setEnabledProtocols(String[] protocolVersions)
      Controls which particular protocol versions are enabled for use on this connection. I perform setting before a server negotiation.
      Parameters:
      protocolVersions - The protocol versions.
    • setEndpointCheckingEnabled Link icon

      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
    • setHostnameVerifier Link icon

      public void setHostnameVerifier(HostnameVerifier newHostnameVerifier)
      Override the default HostnameVerifier to use.
      Parameters:
      newHostnameVerifier - The HostnameVerifier implementation to set or null to disable.
      Since:
      3.4
    • setKeyManager Link icon

      public void setKeyManager(KeyManager newKeyManager)
      Sets a KeyManager to use.
      Parameters:
      newKeyManager - The KeyManager implementation to set.
      See Also:
    • setTrustManager Link icon

      public void setTrustManager(TrustManager newTrustManager)
      Override the default TrustManager to use.
      Parameters:
      newTrustManager - The TrustManager implementation to set.
      See Also: