Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spajus/gmail4j
Gmail API for Java
https://github.com/spajus/gmail4j
Last synced: 7 days ago
JSON representation
Gmail API for Java
- Host: GitHub
- URL: https://github.com/spajus/gmail4j
- Owner: spajus
- License: apache-2.0
- Created: 2012-08-23T04:37:46.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-25T14:39:25.000Z (over 10 years ago)
- Last Synced: 2025-01-10T15:42:56.494Z (14 days ago)
- Language: Java
- Size: 2.89 MB
- Stars: 44
- Watchers: 12
- Forks: 28
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: license.txt
Awesome Lists containing this project
README
Gmail4J - Gmail API for Java
============================
Gmail4J is a simple, object oriented library for accessing Gmail services from Java.Use with Maven
--------------
Add the dependency to your pom.xml:```xml
com.googlecode.gmail4j
gmail4j
0.4```
Or use the latest and greatest snapshot:
```xml
com.googlecode.gmail4j
gmail4j
0.5-SNAPSHOT```
Example code
------------### Get unread messages
```java
GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List messages = client.getUnreadMessages();
for (GmailMessage message : messages) {
System.out.println(message);
}
```### Get messages by subject
```java
GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List messages = client.getMessagesBy(GmailClient.EmailSearchStrategy.SUBJECT,
"Test mail subject. Unicode: ąžuolėlį");
for (GmailMessage message : messages) {
System.out.println(message);
}
```### Get messages by sent date greater than
```java
GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List messages = client.getMessagesBy(GmailClient.EmailSearchStrategy.DATE_GT,
new Date().toString());
for (GmailMessage message : messages) {
System.out.println(message);
}
```### Get messages by keyword
```java
GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List messages = client.getMessagesBy(
GmailClient.EmailSearchStrategy.KEYWORD,"Unicode");
for (GmailMessage message : messages) {
System.out.println(message);
}
```### Get unread messages via proxy
```java
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 messages = client.getUnreadMessages();
for (GmailMessage message : messages) {
System.out.println(message);
}
```There are more examples in API docs.
Compiling
---------
To build a jar, run:`mvn clean package`
You will be asked for valid Gmail account username/password to run the tests. You can register
Gmail account for this purpose or use your own. Registering fresh test account is recommended.You can also skip tests when building a jar:
`mvn clean package -Dmaven.test.skip=true`
Maven Site
----------
For reports, API docs and more, please check [Gmail4j Maven Site](http://spajus.github.com/gmail4j/0.4/).[Changelog](https://github.com/spajus/gmail4j/blob/master/changelog.txt)