CrazyIvan1974
CrazyIvan1974

Reputation: 437

Why am I getting a javax.mail.NoSuchProviderException when attempting to access Gmail from Android?

I am getting this exception while attempting to use the Gmail IMAP API. Here is a segment of my code.

session = Session.getDefaultInstance(props, null);

// Exception occurs on the line below
store = (GmailSSLStore) session.getStore("gimaps");

store.connect(userID,password);

References:

https://java.net/projects/javamail/lists/users/archive/2012-08/message/0

https://javamail.java.net/nonav/docs/api/com/sun/mail/gimap/package-summary.html

Upvotes: 2

Views: 555

Answers (1)

CrazyIvan1974
CrazyIvan1974

Reputation: 437

I didn't get past the exception until I manually added the gmail IMAP provider to the session:

session = Session.getDefaultInstance(props, null);

// Adding Provider here corrected issue
session.addProvider(new Provider(Provider.Type.STORE, "gimaps", "com.sun.mail.gimap.GmailSSLStore","Oracle","1.5.4"));

store = (GmailSSLStore) session.getStore("gimaps");

store.connect(userID,password);

This information came from the gimap.jar's "META-INF/javamail.providers" file.

The root cause of the problem is likely the availability of the "javamail.providers" file during the Session's loadProviders() method. See http://glassfish.sourcearchive.com/documentation/2plus-pb58g-4/classjavax_1_1mail_1_1Session_d90c688f88969065bb3db9716d1ab84a.html.

Upvotes: 1

Related Questions