Giter Site home page Giter Site logo

gmail4j's Introduction

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:

<dependency>
  <groupId>com.googlecode.gmail4j</groupId>
  <artifactId>gmail4j</artifactId>
  <version>0.4</version>
</dependency>

Or use the latest and greatest snapshot:

<dependency>
  <groupId>com.googlecode.gmail4j</groupId>
  <artifactId>gmail4j</artifactId>
  <version>0.5-SNAPSHOT</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 messages by subject

GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List<GmailMessage> 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

GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List<GmailMessage> messages = client.getMessagesBy(GmailClient.EmailSearchStrategy.DATE_GT,
        new Date().toString());
for (GmailMessage message : messages) {
    System.out.println(message);
}

Get messages by keyword

GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection(LoginDialog.getInstance().show("Enter Gmail Login"));
client.setConnection(connection);
final List<GmailMessage> messages = client.getMessagesBy(
        GmailClient.EmailSearchStrategy.KEYWORD,"Unicode");
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);
}

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.

Changelog

gmail4j's People

Contributors

fcojean avatar pavelvinogradov avatar spajus avatar strusewych avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmail4j's Issues

master compilation

Can you explain how to compile the master repository? When I try to do it I get

[INFO] --- maven-source-plugin:2.1.2:jar (default) @ gmail4j ---
[INFO] Building jar: /home/eianni/Bravofly/BravoflyGitRep/gmail4j/target/gmail4j-0.5-SNAPSHOT-sources.jar
[INFO]
[INFO] --- maven-gpg-plugin:1.1:sign (sign-artifacts) @ gmail4j ---
GPG Passphrase: ***************

Do I need to configure something about GPG?

Get message body

I need to get the body of my messages, but message.getContentText() gives an error: java.lang.UnsupportedOperationException: This GmailMessage implementation does not provide getContentText()

I'm using version 0.5 snapshot, and instantiating an RssGmailClient. When trying an ImapGmailClient, as suggested in one of the issues here, the error is java.lang.NoClassDefFoundError: javax/mail/search/SearchTerm

Compilation Error when adding the gmail4j library to the gradle

i'm trying to build the app after adding the implementation group: 'com.googlecode.gmail4j', name: 'gmail4j', version: '0.4'

I got this error: Program type already present: com.sun.mail.smtp.SMTPOutputStream

this is my all dependencies:
dependencies {
// compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

//noinspection GradleCompatible
//compile 'com.android.support:appcompat-v7:24.2.1'//original
implementation 'com.android.support:appcompat-v7:26.0.2'//new
implementation 'com.android.support:design:24.2.1'
implementation 'com.android.support:support-v4:24.2.1'
implementation 'com.android.support:support-vector-drawable:24.2.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation files('libs/activation.jar')
implementation files('libs/additionnal.jar')
implementation files('libs/mail.jar')
implementation 'com.github.florent37:camerafragment:1.0.7'

//add lib of photoview
implementation 'com.github.chrisbanes:PhotoView:1.2.6'

//Add Gmail Dependency
implementation group: 'com.googlecode.gmail4j', name: 'gmail4j', version: '0.4'

}

GmailClient.EmailSearchStrategy does not compile

I'm trying the sample code given here with either version 0.4 or 0.5 snapshot. In both GmailClient.EmailSearchStrategy does not compile.

The enum exists in the source code that can be downloaded from here, but apparently isn't in the jars?

Gmail access in android

Hello ,
i need the same access of gmail mails and have to show in my application in android,so can you please help me to modify this jar in android because its crashing there because of views and some classes not supported there.

Unable to login to Google Apps Account

When attempting to login to at google apps account where the domain name is required after the "@" i.e. notarealemployee"@"finalconcept.com.au the IMapGmailConnection anyway appends "@google.com" to the username.

Maybe a better option would be to first check for the @ symbol in the username then if not present append the @google.com

If I am misusing the lib please let me know, thanks

store.connect(gmailImapHost, loginCredentials.getUsername()
                .concat(CommonConstants.GMAIL_EXTENTION),
                new String(loginCredentials.getPasword()));

Getting "Failed getting message subject exception is shown" exception when the subject is actually retrieved

m contacting you since Im using your gmail4j java library in order to get some messages from a gmail account. This is being used just for testing matters and I have some tests running in concurrence agains the same account in order to retrieve the subjects of certain emails.
THe issue Im dealing with is that despite all the subjects are retrieved as expected, the com.googlecode.gmail4j.GmailException: Failed getting message subject exception is shown.
As you can see in this assert, the subjects matches which means the email's subject was found "Code: OK, Message: Going to verify if email subject: Failure alert opened -- Crash-Dummy-BE-30050 matches with expected one: Failure alert opened -- Crash-Dummy-BE-30050 "

Any idea?

Maven Repository

Please,

Could you update the maven repository? I'm try to use the artefact and somethings like the method "client.getMessagesBy()" aren't working.

Thank you.

ImapGmailClient no longer working

No Gmail4j method calls are working for me anymore...

com.googlecode.gmail4j.GmailException: ImapGmailClient failed marking all GmailMessage as read
at com.googlecode.gmail4j.javamail.ImapGmailClient.markAllAsRead(ImapGmailClient.java:340)

com.googlecode.gmail4j.GmailException: Failed getting unread messages
at com.googlecode.gmail4j.javamail.ImapGmailClient.getUnreadMessages(ImapGmailClient.java:185)

Everything was working fine as recently as last week. Do you know if something has changed? Is anyone else encountering this issue?

Thanks!
Andrew

Can't support unicode character in message

Hi Tomas,

I was trying to use this library to retrieve message but found it didn't support unicode character in message. Can you please look into it? Gmail4j is a great library for Gmail. I love it!

Thanks!

Mercury

Only 20 unread messages returning

When following the code sample and asking for

final List messages = client.getUnreadMessages();

I'm getting only the latest 20 unread messages. There are more in my account and I need to have them. What's the way to achieve that?

Getting the source from a message

Hello,

Is it in any way possible to get the source from an unread email?
I got a URL in the mail and when I print the content it just says "link".
I need to get the href from the link.

Thanks in advance.
Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.