Java POP3 Component
The POP3 (Post Office Protocol v3) component provides a simple
interface for retrieving electronic mail messages from a POP3 server.
The POP3 component implements standards in RFC 1725 and RFC 1939.
Download Secure iNet Factory Evaluation
Features
- APOP and plain-text authentication - With built in support
for both APOP (RFC 1939) and plain text authentication modes,
the POP3 component provides authentication support for the most
popular POP3 servers.
- File attachment retrieval - A streamlined API provides easy
to use methods for retrieving attachments from a POP3 message.
- Automatic message delete support - A convenient method to
optionally delete messages automatically after download from
POP3 server.
- TOP support - Per RFC 1939 the TOP command allows preview
of the first X lines without downloading the entire message
body.
- POP SSL - Support for retrieving messages securely using POP SSL.
Code Example
The following example demonstrates how to retrieve email from
a POP3 server.
/*
* @(#)PopExample.java
*
* Copyright (c) 2001-2002 JScape
* 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information of
* JScape. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with JScape.
*/
import com.jscape.inet.pop.*;
import com.jscape.inet.email.*;
import com.jscape.inet.mime.*;
import java.util.Enumeration;
import java.io.*;
public class PopExample {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// get messages from Pop mailbox
public void getMessages(String hostname, String username, String password) throws PopException,
MimeException, IOException {
// create new Pop instance
Pop pop = new Pop(hostname,username,password);
// connect to POP3 server and login
pop.connect();
System.out.println("Retrieving messages...");
// retrieve all messages from POP3 server
Enumeration messages = pop.getMessages();
if(!messages.hasMoreElements()) {
System.out.println("No messages found");
}
// print out contents of each message to console
while(messages.hasMoreElements()) {
System.out.println("-- begin message --");
EmailMessage msg = (EmailMessage)messages.nextElement();
System.out.println(new String(msg.getMessage()));
System.out.println("-- end message --");
if(messages.hasMoreElements()) {
System.out.print("ENTER for next message or type QUIT to quit: ");
String command = reader.readLine();
if(command.equalsIgnoreCase("quit")) {
break;
}
}
}
// disconnect from POP3 server
pop.disconnect();
}
public static void main(String[] args) {
String hostname;
String username;
String password;
try {
System.out.print("Enter POP3 hostname (e.g. mail.domain.com): ");
hostname = reader.readLine();
System.out.print("Enter POP3 Username: ");
username = reader.readLine();
System.out.print("Enter POP3 Password: ");
password = reader.readLine();
PopExample example = new PopExample();
example.getMessages(hostname,username,password);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
|
|