Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail API returning status code 400, error "Mail service not enabled"

I recently started seeing the following error from the gmail API:

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Mail service not enabled",
    "reason" : "failedPrecondition"
  } ],
  "message" : "Mail service not enabled"
}

Every gmail api call I've tested causes the error, but the following code shows a normal example:

public static List<String> getThreadIdsFromRFC822MessageIds(Collection<String> messageIds, User u) throws IOException, NoOauthCredentialsException {
    List<String> queryTerms = new ArrayList<>();
    for (String messageId: messageIds) {
        queryTerms.add("rfc822msgid:" + messageId);
    }
    String queryString = Joiner.on(" OR ").join(queryTerms);
    String fieldSelectionString = "messages/threadId";

    ListMessagesResponse messages = executeMessageQuery(u, queryString, fieldSelectionString);
    List<String> threadIds = new ArrayList<>();
    if (messages.getMessages() != null) {
        for (Message m : messages.getMessages()) {
            threadIds.add(m.getThreadId());
        }
    }
    return threadIds;
}

private static ListMessagesResponse executeMessageQuery(User u, String queryString, String fieldSelectionString) throws IOException, NoOauthCredentialsException {
    assert fieldSelectionString.length() > 0;
    Gmail g = GmailAPIHelper.getGmailService(u);
    Gmail.Users.Messages.List query = g.users().messages().list("me").setQ(queryString).setFields(fieldSelectionString);
    ListMessagesResponse messages = executeAndLog(query, u);
    return messages;
}

Where executeAndLog calls .execute on the Gmail.Users.Messages.List object.

This error is only affecting a very small number of my users, and the error message suggests that it is a problem with permissions. I expect that asking my users to reauthorize will fix the issue, but I am concerned that I'm getting this error message instead of the more usual 401 when there's a permission problem. Has anyone seen this error?

like image 769
Lucas Sloan Avatar asked Jul 29 '15 06:07

Lucas Sloan


1 Answers

Your trial period could have expired. Check your status at admin.google.com

like image 161
Sandeep Muthangi Avatar answered Nov 02 '22 03:11

Sandeep Muthangi