hii.. aku mau berbagi code nih untuk retrieve email dengan menggunakan javamail, library javamail tidak disediakan sun secara default pada paket JDK, jadi kita harus meng-import library ini terlebih dahulu, javamail bisa anda dapatkan disini
berikut adalah potongan code dari kelas utama-nya..

/**
* @(#)InboxReader.java
*
*
* @author Marudut M
* @version 1.00 2009/6/5
*/
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.internet.InternetAddress;
import javax.mail.search.FlagTerm;
import java.io.*;

public class InboxReader {
private String host;
private String user;
private String password;

public InboxReader(){
host = "";
user = "";
password = "";
}

public InboxReader(String host, String user, String password){
this.host = host;
this.user = user;
this.password = password;
}

//--------- setter ------------
public void setHost(){
this.host = host;
}
public void setUser(){
this.user = user;
}
public void setPassword(){
this.password = password;
}

//-------- getter ------------
public String getHost(String host){
return host;
}
public String getUser(String user){
return user;
}
public String getPassword(String password){
return password;
}

public void readInbox(){
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect(host, user, password);

//mencari semua email yang ada di Inbox
Folder inbox = store.getFolder("Inbox");
System.out.println(store);
inbox.open(Folder.READ_ONLY);
int countInbox = inbox.getMessageCount();
System.out.println("Total Inbox: " + countInbox);

// Message numebers start at 1
for(int i = countInbox; i > 0; i--) {
// Get a message by its sequence number
Message m = inbox.getMessage(i);
// Get some headers
Date date = m.getSentDate();
Address[] from = m.getFrom();
String subj = m.getSubject();

String mimeType = m.getContentType();
k++;
System.out.println("-------------------- Pesan " +k+ " ------------------");
System.out.print("Tanggal: " + date);
System.out.print("\nDari: " + from[]);\
System.out.print("\nSubjek: " + subj);
System.out.println("\nIsi Pesan: ");

Object o = m.getContent();

//jika isi pesan instance dari String
if (o instanceof String) {
System.out.println("**This is a String Message**");
String isiPesan = (String)o;

totString = isiPesan.length();
System.out.println("Total String: " + totString);
System.out.println("Content Type: " + m.getContentType());
System.out.println(isiPesan);
}//jika isi pesan instance dari Multipart
else if (o instanceof Multipart){
System.out.print("**This is a Multipart Message. ");
Multipart mp = (Multipart)o;
int count3 = mp.getCount();
System.out.println("It has " + count3 + " BodyParts in it**");
for (int j = 0; j < count3; j++) {
// Part are numbered starting at 0
BodyPart b = mp.getBodyPart(0);

String mimeType2 = b.getContentType();
System.out.println( "BodyPart " + (j + 1) + " is of MimeType " + mimeType);

Object o2 = b.getContent();
if (o2 instanceof String){
//System.out.println("**This is a String BodyPart**");
String isiPesan = (String)o2;
int totString = string2.length();
System.out.println("Total String: " + totString);
System.out.println("Content Type: " + m.getContentType());
System.out.println(isiPesan);
}else if (o2 instanceof Multipart) {
System.out.print("**This BodyPart is a nested Multipart. ");
Multipart mp2 = (Multipart)o2;
int count2 = mp2.getCount();
System.out.println("It has " + count2 + "further BodyParts in it**");
}else if (o2 instanceof InputStream) {
System.out.println("**This is an InputStream BodyPart**");
}
} //End of for
}
else if (o instanceof InputStream) {
System.out.println("**This is an InputStream message**");
InputStream is = (InputStream)o;
// Assumes character content (not binary images)
int c;
while ((c = is.read()) != -1) {
System.out.write(c);
}
}
}
inbox.close(true);
store.close();
} catch (IOException ioe){
ioe.printStackTrace();
System.exit(0);
} catch (NoSuchProviderException e) {
e.printStackTrace();
System.exit(1);
} catch (MessagingException e) {
e.printStackTrace();
System.exit(2);
}
}
}

untuk kelas tester-nya (kelas yang akan menggunakan kelas ini), bisa anda buat seperti ini:
import java.io.*;
public class testerGmailInboxReader {
public static void main(String args[]) throws IOException{
String mailhost, username, passwd;
System.out.print("Host mail server (Gmail: imap.gmail.com): ");
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
mailhost = br1.readLine();
System.out.print("Username: ");
BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
username = br2.readLine();
System.out.print("Password: ");
BufferedReader br3 = new BufferedReader(new InputStreamReader(System.in));
passwd = br3.readLine();

GmailInboxReader g = new GmailInboxReader(mailhost, username, passwd);
g.readInbox();
}
}