-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to login to Google Apps Account #5
Comments
PS: I am using the MVN dep 0.4
|
Here is another option: Create a subclass called GoogleAppsImapGmailConnection that extends ImapGmailConnection and overrides the I had to create a new store var, but it only seems to be used in the openGmailStore and disconnect methods package au.com.finalconcept.imapclient;
import java.io.IOException;
import java.util.List;
import javax.mail.Store;
import com.googlecode.gmail4j.GmailException;
import com.googlecode.gmail4j.GmailMessage;
import com.googlecode.gmail4j.auth.Credentials;
import com.googlecode.gmail4j.javamail.ConnectionInfo;
import com.googlecode.gmail4j.javamail.ImapConnectionHandler;
import com.googlecode.gmail4j.javamail.ImapGmailClient;
import com.googlecode.gmail4j.javamail.ImapGmailConnection;
import com.googlecode.gmail4j.javamail.ImapGmailLabel;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
ImapGmailClient client;
ImapGmailConnection connection;
List<GmailMessage> messages;
client = new ImapGmailClient(ImapGmailLabel.INBOX);
Credentials creds;
creds = new Credentials(args[0], args[1].toCharArray());
connection = new GoogleAppsImapGmailConnection();
connection.setLoginCredentials(creds);
client.setConnection(connection);
try {
messages = client.getUnreadMessages();
} catch (Exception e) {
e.printStackTrace();
return;
}
for (GmailMessage message : messages) {
System.out.println(message);
}
}
public static class GoogleAppsImapGmailConnection extends ImapGmailConnection {
private Store store;
/**
* Opens Gmail {@link Store}
*
* @return singleton instance of Gmail {@link Store}
*/
@Override
public Store openGmailStore() {
try {
// if stort object instance is not null and the service
// connection state
// is connected then close this service and terminate its
// connection.
// Note : due to security concerns gmail imap only allow max 10
// connections because of this reason any existing connection
// that
// is open should terminate.
if (isConnected()) {
disconnect();
}
store = getSession().getStore("imaps");
store.addConnectionListener(new ImapConnectionHandler(
new ConnectionInfo(loginCredentials.getUsername(), getGmailImapHost(), getGmailImapPort())));
store.connect(getGmailImapHost(), loginCredentials.getUsername(), new String(loginCredentials.getPasword()));
setConnected(store.isConnected());
} catch (final Exception e) {
throw new GmailException("Failed opening Gmail IMAP store", e);
}
return store;
}
/**
* Disconnects from Gmail
*/
public void disconnect() {
try {
if (isConnected()) {
store.close();
}
} catch (final Exception e) {
//log.warn("Failed closing Gmail IMAP store", e);
}
}
}
} |
This issue was fixed in trunk. Maybe it published to maven repository under version 0.5-SNAPSHOT. |
thanks mate, I will keep a look out for it |
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
The text was updated successfully, but these errors were encountered: