Gmail4J
Gmail4J is a simple, object oriented library for accessing Gmail services from Java.
Use with Maven
First add dev.java.net Maven repository to your pom.xml or settings.xml:
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
</repository>
<!-- other repositories -->
</repositories>
Then add the dependency to your pom.xml:
<dependency>
<groupId>com.googlecode</groupId>
<artifactId>gmail4j</artifactId>
<version>0.3</version>
</dependency>
Example code
Get unread messages
GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List<GmailMessage> messages = client.getUnreadMessages();
for (GmailMessage message : messages) {
System.out.println(message);
}
Get unread messages via proxy
GmailClient client = new RssGmailClient();
HttpGmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
connection.setProxy("proxy.example.com", 8080);
connection.setProxyCredentials(LoginDialog.getInstance().show("Enter Proxy Login"));
client.setConnection(connection);
final List<GmailMessage> messages = client.getUnreadMessages();
for (GmailMessage message : messages) {
System.out.println(message);
}