Secure iNet Factory

com.jscape.inet.smtpssl
Class SmtpSsl

java.lang.Object
  extended by com.jscape.inet.smtp.Smtp
      extended by com.jscape.inet.smtpssl.SmtpSsl
All Implemented Interfaces:
java.io.Serializable

public class SmtpSsl
extends Smtp

Implements the basic functionality of a secure SMTP client using SSL/TLS. Client supports both implicit SSL/TLS on port 465 (default) and explicit SSL/TLS using STARTTLS command on port 25.

Example Usage (implicit SSL/TLS):

 // create new instance
 SmtpSsl smtp = new SmtpSsl("smtp.myserver.com",465);
  // address the message
 EmailMessage message = new EmailMessage();
 message.setTo("mjones@myserver.com");
 message.setFrom("jsmith@myserver.com");
 message.setSubject("Meeting today at 8");
 message setBody("see you then");
  // connect, send the message, disconnect
 try
 {
   smtp.connect();
   smtp.send(message);
   smtp.disconnect();
 }
 catch(Exception e)
 {
   System.out.println(e);
 }
 

Example Usage (explicit SSL/TLS using STARTTLS command):

 // create new instance
 SmtpSsl smtp = new SmtpSsl("smtp.myserver.com",25);
 smtp.setConnectionType(SmtpSsl.STARTTLS);
  // address the message
 EmailMessage message = new EmailMessage();
 message.setTo("mjones@myserver.com");
 message.setFrom("jsmith@myserver.com");
 message.setSubject("Meeting today at 8");
 message setBody("see you then");
  // connect, send the message, disconnect
 try
 {
   smtp.connect();
   smtp.send(message);
   smtp.disconnect();
 }
 catch(Exception e)
 {
   System.out.println(e);
 }
 

See Also:
Serialized Form

Field Summary
static int DEFAULT_PORT
          The default port to connect to for secure SMTP over SSL connections.
static int IMPLICIT_SSL
          Connection type for implicit SSL/TLS connections on port 465.
static int STARTTLS
          Connection type for explicit SSL/TLS connections using STARTTLS command on port 25.
 
Fields inherited from class com.jscape.inet.smtp.Smtp
AUTH_CRAM_MD5, AUTH_LOGIN
 
Constructor Summary
SmtpSsl(java.lang.String hostname)
          Constructs new SmtpSsl instance.
SmtpSsl(java.lang.String hostname, int port)
          Constructs new SmtpSsl instance.
 
Method Summary
 void clearProxySettings()
          Clears proxy server values.
 void connect()
          Securely connects to SMTP server using SSL.
 void disconnect()
          Disconnects from SMTP server.
 int getConnectionType()
          Gets the connection type for this session.
 void setClientCertificates(java.lang.String filename, java.lang.String password)
          Sets optional client certificate to be used during authentication.
 void setClientCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional client certificate to be used during authentication.
 void setConnectionType(int mode)
          Sets the connection type for this session.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the username and password to use when for authentication with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this connection.
 void setServerCertificates(java.lang.String filename, java.lang.String password)
          Sets optional server certificate to be used during authentication.
 void setServerCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional server certificate to be used during authentication.
 void setSSLContext(javax.net.ssl.SSLContext context)
          Sets SSL context for this connection.
 
Methods inherited from class com.jscape.inet.smtp.Smtp
addSmtpListener, getConnectTimeout, getDebugStream, getHostname, getPort, getReadTimeout, getTimeout, isConnected, isDebug, issueCommand, login, login, main, removeSmtpListener, send, send, send, setConnectTimeout, setDebug, setDebugStream, setHeloAddress, setHostname, setPort, setReadTimeout, setTimeout
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPLICIT_SSL

public static final int IMPLICIT_SSL
Connection type for implicit SSL/TLS connections on port 465. Value of 0.

See Also:
setConnectionType(int), STARTTLS, Constant Field Values

STARTTLS

public static final int STARTTLS
Connection type for explicit SSL/TLS connections using STARTTLS command on port 25. Value of 1.

See Also:
setConnectionType(int), IMPLICIT_SSL, Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to connect to for secure SMTP over SSL connections. Value of 465.

See Also:
Constant Field Values
Constructor Detail

SmtpSsl

public SmtpSsl(java.lang.String hostname)
Constructs new SmtpSsl instance.

Parameters:
hostname - the SMTP server hostname

SmtpSsl

public SmtpSsl(java.lang.String hostname,
               int port)
Constructs new SmtpSsl instance.

Parameters:
hostname - the SMTP server hostname
port - the SMTP SSL server port
Method Detail

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password)
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12

setConnectionType

public void setConnectionType(int mode)
Sets the connection type for this session.

Parameters:
mode - a valid connection type
See Also:
IMPLICIT_SSL, STARTTLS

getConnectionType

public int getConnectionType()
Gets the connection type for this session. Default is IMPLICIT_SSL

Returns:
the connection type
See Also:
IMPLICIT_SSL, STARTTLS

setSSLContext

public void setSSLContext(javax.net.ssl.SSLContext context)
Sets SSL context for this connection.

Parameters:
context - an SSLContext instance
See Also:
SSLContext

setServerCertificates

public void setServerCertificates(java.lang.String filename,
                                  java.lang.String password)
Sets optional server certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the server certificate
password - the keystore password

setServerCertificates

public void setServerCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
Sets optional server certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the server certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the #clearProxySettings method.

Overrides:
setProxyAuthentication in class Smtp
Parameters:
proxyUsername - the proxy username
proxyPassword - the proxy password
See Also:
clearProxySettings()

setProxyHost

public void setProxyHost(java.lang.String proxyHostname,
                         int proxyPort)
Sets the proxy hostname and port for this connection. To clear these settings invoke the #clearProxySettings method.

Overrides:
setProxyHost in class Smtp
Parameters:
proxyHostname - the hostname or ip address of the proxy server
proxyPort - the port of the proxy server
See Also:
clearProxySettings()

setProxyType

public void setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.

Overrides:
setProxyType in class Smtp
Parameters:
proxyType - The proxy type. Valid values: HTTP, SOCKS5

clearProxySettings

public void clearProxySettings()
Clears proxy server values.

Overrides:
clearProxySettings in class Smtp

connect

public void connect()
             throws SmtpException
Securely connects to SMTP server using SSL.

Overrides:
connect in class Smtp
Throws:
SmtpException - thrown for I/O or SMTP related error

disconnect

public void disconnect()
                throws SmtpException
Disconnects from SMTP server.

Overrides:
disconnect in class Smtp
Throws:
SmtpException - thrown to handle SMTP and I/O related errors
See Also:
SmtpException

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved