Using the ImapSsl class

Top  Previous  Next

The ImapSsl class provides an easy to use client interface for securely communicating with IMAP servers using SSL/TLS.  The ImapSsl class provides both implicit and explicit SSL/TLS connections.  Implicit SSL/TLS connections are made by default using remote port 993.  Explicit SSL/TLS connections are made using an unencrypted connection to port 143 of an IMAP server and then switching to an encrypted mode using the STARTTLS command prior to sending any additional data.

 

Example

 

The example below demonstrates connecting using implicit SSL/TLS on port 993

 

// create new ImapSsl instance

ImapSsl ssl = new ImapSsl(hostname,993,username,password);                        

                 

// establish implicit SSL connection on port 993

ssl.connect();

                 

// get messages and print out subject

Enumeration e = ssl.getMessages();

while(e.hasMoreElements()) {

 EmailMessage msg = (EmailMessage)e.nextElement();

 System.out.println("Subject: " + msg.getSubject());                                

}

                 

// disconnect

ssl.disconnect();

 

 

Example

 

The example below demonstrates connecting using explicit SSL/TLS and STARTTLS command on port 143.

 

// create new ImapSsl instance

ImapSsl ssl = new ImapSsl(hostname,143,username,password);                        

 

// set connection type

ssl.setConnectionType(ImapSsl.STARTTLS);

                 

// establish explicit SSL connection on port 143 using STARTTLS command

ssl.connect();

                 

// get messages and print out subject

Enumeration e = ssl.getMessages();

while(e.hasMoreElements()) {

 EmailMessage msg = (EmailMessage)e.nextElement();

 System.out.println("Subject: " + msg.getSubject());                                

}

                 

// disconnect

ssl.disconnect();

 

 

 





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC