Retrieving email securely from Gmail using POP SSL
The free Google email service Gmail offers over 2GB of storage space prompting many people to signup for accounts. In order to access your account you must however use a secure POP connection using SSL.
The purpose of this article is to demonstrate how to connect to a Gmail account using the Java com.jscape.inet.popssl.PopSsl class found in Secure iNet Factory.
The procedures in this article may also apply to other POP servers which provide secure SSL/TLS access.
For a tutorial on sending email using Gmail see Sending email securely using Gmail and SMTP SSL.
- A Gmail account. As of this writing this service is still in beta. If you do not have an account you must get invited to open an account from someone who already has one.
- JDK 1.2.2 or above and Secure iNet Factory
Note
If using a JDK prior to JDK 1.4 then you must download and install the JSSE (Java Secure Socket Extensions). Instructions for doing this are provided in the Secure iNet Factory User Guide.
01 import com.jscape.inet.email.*;
02 import com.jscape.inet.popssl.*;
03
04
05 public class PopSslTest {
06
07 public static void main(String[] args) {
08 String hostname = "pop.gmail.com";
09 String username = "user@gmail.com";
10 String password = "password";
11 try {
12 // create new PopSsl instance
13 PopSsl ssl = new PopSsl(hostname,995,username,password);
14 ssl.setDebug(true);
15
16 // establish SSL/TLS connection
17 ssl.connect();
18
19 // get message count
20 int count = ssl.getMessageCount();
21
22 // get each message and print subject
23 for(int i = 1; i <= count; ++i) {
24 EmailMessage msg = ssl.getMessage(i);
25 System.out.println("Subject: " + msg.getSubject());
26 }
27
28 // disconnect
29 ssl.disconnect();
30 } catch(Exception e) {
31 e.printStackTrace();
32 }
33 }
34
35 }
- Lines 1-3. Import necessary classes.
- Lines 8-10. Define hostname, username and password variables.
- Line 13. Create new PopSsl instance.
- Line 17. Establish secure connection.
- Line 20. Get message count.
- Lines 23-26. Get each message and print Subject header to console.
- Line 29. Disconnect
In this article you learned how to securely retrieve email from a Gmail server using the secure POP classes provided in Secure iNet Factory.
The procedures in this article may also apply to other POP servers which provide secure SSL/TLS access.
|