Overview
This article will demonstrate how to communicate with a POP3 server over SSL using Secure iNet Factory.
Code Example
Download POPSSLEx.java
01 import java.util.Enumeration;
02 import com.jscape.inet.email.EmailMessage;
03 import com.jscape.inet.popssl.PopSsl;
04
05
06 public class POPSSLEx
07 {
08 public static void ImplicitSSL_TLS()
09 {
10 try
11 {
12 String hostname = "host";
13 String username = "username";
14 String password = "password";
15 // create new PopSsl instance
16 PopSsl ssl = new PopSsl(hostname,995,username,password);
17 // establish SSL/TLS connection
18 ssl.connect();
19 // get messages and print subject
20 Enumeration e = ssl.getMessages();
21 while(e.hasMoreElements())
22 {
23 EmailMessage msg = (EmailMessage)e.nextElement();
24 System.out.println("Subject: " + msg.getSubject());
25 }
26 // disconnect
27 ssl.disconnect();
28 }
29 catch (Exception e)
30 {
31 e.printStackTrace();
32 }
33 }
34
35 public static void ExplicitSSL_TLS()
36 {
37 try
38 {
39 String hostname = "host";
40 String username = "username";
41 String password = "password";
42 // create new PopSsl instance
43 PopSsl ssl = new PopSsl(hostname,110,username,password);
44 // set connection type
45 ssl.setConnectionType(PopSsl.STARTTLS);
46 // establish SSL/TLS connection
47 ssl.connect();
48 // get messages and print subject
49 Enumeration e = ssl.getMessages();
50 while(e.hasMoreElements())
51 {
52 EmailMessage msg = (EmailMessage)e.nextElement();
53 System.out.println("Subject: " + msg.getSubject());
54 }
55 // disconnect
56 ssl.disconnect();
57 }
58 catch (Exception e)
59 {
60 e.printStackTrace();
61 }
62 }
63
64 public static void main(String[] args)
65 {
66 ImplicitSSL_TLS();
67 ExplicitSSL_TLS();
68 }
69 }
Lines 1-3 : Necessary Import Statements. Lines 8-33 : Connect to POP3 server over SSL on port 995. Lines 35-62 : Connect to POP3 server over SSL on port 110. This function demonstrates connecting using explicit SSL and STLS command.
|
Comments