public class ImapSsl extends Imap
Example Usage (implicit SSL/TLS):
// new instance with hostname, SSL port, username and password
ImapSsl imap = new ImapSsl("imap4.myserver.com",993,"jsmith","secret");
try {
// connect to IMAP4 server
imap.connect();
// get messages
int messageCount = imap.getMessageCount();
for(int i = 1; i <= messageCount(); ++i) {
EmailMessage em = imap.getMessage(i);
}
// disconnect
imap.disconnect();
}
catch(Exception e) {
System.out.println(e);
}
Example Usage (explicit SSL/TLS using STARTTLS command):
// new instance with hostname, SSL port, username and password
ImapSsl imap = new ImapSsl("imap4.myserver.com",143,"jsmith","secret");
imap.setConnectionType(ImapSsl.STARTTLS);
try {
// connect to IMAP4 server
imap.connect();
// get messages
int messageCount = imap.getMessageCount();
for(int i = 1; i <= messageCount(); ++i) {
EmailMessage em = imap.getMessage(i);
}
// disconnect
imap.disconnect();
}
catch(Exception e) {
System.out.println(e);
}
Imap.Authentication| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_PORT
The default port to connect to for secure IMAP over SSL connections (993).
|
static int |
IMPLICIT_SSL
Connection type for implicit SSL/TLS connections on port 993.
|
static int |
STARTTLS
Connection type for explicit SSL/TLS connections using STARTTLS command on port 143.
|
AUTH_CRAM_MD5, AUTH_LOGIN, AUTH_XOAUTH2, FLAG_ANSWERED, FLAG_DELETED, FLAG_DRAFT, FLAG_FLAGGED, FLAG_MODE_ADD, FLAG_MODE_DELETE, FLAG_MODE_REPLACE, FLAG_RECENT, FLAG_SEEN| Constructor and Description |
|---|
ImapSsl(java.lang.String hostname,
int port,
java.lang.String username,
java.lang.String password)
Creates a new ImapSsl instance.
|
ImapSsl(java.lang.String hostname,
java.lang.String username,
java.lang.String password)
Creates a new ImapSsl instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearProxySettings()
Clears proxy server values.
|
ImapSsl |
connect()
Establishes secure SSL connection to IMAP server.
|
void |
disconnect()
Disconnects from IMAP 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.
|
addImapListener, append, append, close, createMailbox, deleteMailbox, deleteMessage, deleteMessages, expunge, getAuthMode, getConnectTimeout, getDebugStream, getHostname, getMailboxes, getMessage, getMessageCount, getMessageHeader, getMessageHeaders, getMessageID, getMessages, getMessages, getMessages, getMessagesWithFlags, getMessagesWithFlags, getMessagesWithFlags, getMessageWithFlags, getNewMessageID, getNewMessages, getNewMessagesWithFlags, getPort, getReadTimeout, getTimeout, getUid, getUid, getUsername, isConnected, isDebug, isDelete, issueCommand, listMailboxes, listMailboxes, removeImapListener, renameMailbox, selectMailbox, setAuthentication, setAuthMode, setConnectTimeout, setDebug, setDebugStream, setDelete, setHostname, setPassword, setPort, setReadTimeout, setTimeout, setUsername, store, storepublic static final int IMPLICIT_SSL
setConnectionType(int),
STARTTLS,
Constant Field Valuespublic static final int STARTTLS
setConnectionType(int),
IMPLICIT_SSL,
Constant Field Valuespublic static final int DEFAULT_PORT
public ImapSsl(java.lang.String hostname,
java.lang.String username,
java.lang.String password)
hostname - the IMAP hostnameusername - the IMAP usernamepassword - the IMAP passwordpublic ImapSsl(java.lang.String hostname,
int port,
java.lang.String username,
java.lang.String password)
hostname - the IMAP hostnameusername - the IMAP usernamepassword - the IMAP passwordport - the IMAP SSL portpublic void setClientCertificates(java.lang.String filename,
java.lang.String password)
keytool utility provided in the Sun JDK.
Example:
keytool.exe -import -file x509.cer -keystore your_store_nameThe example above imports the certificate x509.cer into a keystore named your_store_name
filename - the keystore file containing the client certificatepassword - the keystore passwordpublic void setClientCertificates(java.lang.String filename,
java.lang.String password,
java.lang.String storetype)
keytool utility provided in the Sun JDK.
Example:
keytool.exe -import -file x509.cer -keystore your_store_nameThe example above imports the certificate x509.cer into a keystore named your_store_name
filename - the keystore file containing the client certificatepassword - the keystore passwordstoretype - the keystore type valid values include jks and pkcs12public void setConnectionType(int mode)
mode - a valid connection typeIMPLICIT_SSL,
STARTTLSpublic int getConnectionType()
IMPLICIT_SSL,
STARTTLSpublic void setSSLContext(javax.net.ssl.SSLContext context)
context - an SSLContext instanceSSLContextpublic void setServerCertificates(java.lang.String filename,
java.lang.String password)
keytool utility provided in the Sun JDK.
Example:
keytool.exe -import -file x509.cer -keystore your_store_nameThe example above imports the certificate x509.cer into a keystore named your_store_name
filename - the keystore file containing the server certificatepassword - the keystore passwordpublic void setServerCertificates(java.lang.String filename,
java.lang.String password,
java.lang.String storetype)
keytool utility provided in the Sun JDK.
Example:
keytool.exe -import -file x509.cer -keystore your_store_nameThe example above imports the certificate x509.cer into a keystore named your_store_name
filename - the keystore file containing the server certificatepassword - the keystore passwordstoretype - the keystore type valid values include jks and pkcs12public void setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
#clearProxySettings method.setProxyAuthentication in class ImapproxyUsername - the proxy usernameproxyPassword - the proxy passwordclearProxySettings()public void setProxyHost(java.lang.String proxyHostname,
int proxyPort)
#clearProxySettings method.setProxyHost in class ImapproxyHostname - the hostname or ip address of the proxy serverproxyPort - the port of the proxy serverclearProxySettings()public void setProxyType(java.lang.String proxyType)
setProxyType in class ImapproxyType - The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
clearProxySettings in class Imappublic ImapSsl connect() throws ImapException
connect in class ImapImapException - if I/O or IMAP related error occurspublic void disconnect()
throws ImapException
disconnect in class ImapImapException - if I/O or IMAP related error occursImap.connect()Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved