Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6703493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:10:40+00:00 2026-05-26T07:10:40+00:00

i’m trying to access my gmail inbox with java by using socket (not java

  • 0

i’m trying to access my gmail inbox with java by using socket (not java mail api).
i succesfully establish the connection but select inbox command is not recognized. here is my code. and the output i get.

    SSLSocketFactory sslsocketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("imap.gmail.com", 993);

    BufferedReader sin = new BufferedReader(new InputStreamReader(sslsocket.getInputStream()));
    PrintWriter output = new PrintWriter(new OutputStreamWriter(sslsocket.getOutputStream()));

String line;
 output.println("A004 LOGIN my-mail-here my-pass-here");
    output.println("A005 SELECT [GMAIL]/myinbox");
    output.println("A006 LOGOUT");
    output.flush();
    while ((line = sin.readLine()) != null)
    System.out.println(line);

and here is the output i get :

* OK Gimap ready for requests from 78.185.154.27 o19if1214052bkq.44
A005 BAD Unknown command o19if1214052bkq.44
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE
A004 OK my-mail@gmail.com my-name my-surname authenticated (Success)

what may be the problem? login works but select doesn’t work. i tried starttls , it also doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:10:40+00:00Added an answer on May 26, 2026 at 7:10 am

    Because you’re doing it wrong 🙂

    005 SELECT myinbox
    

    will do what you are trying to do.

    A great way to test out these sorts of things is with openssl

    openssl s_client -crlf -connect imap.gmail.com:993

    here’s an example using my gmail account. My Drafts is listed as:

    * LIST (\HasChildren \HasNoChildren) “/” “[Gmail]/Drafts”

    003 select Drafts
    * FLAGS (\Answered \Flagged \Draft \Deleted \Seen $MDNSent Junk $Forwarded NonJunk)
    * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $MDNSent Junk $Forwarded NonJunk \*)] Flags permitted.
    * OK [UIDVALIDITY 620224742] UIDs valid.
    * 0 EXISTS
    * 0 RECENT
    * OK [UIDNEXT 25] Predicted next UID.
    003 OK [READ-WRITE] Drafts selected. (Success)
    

    That being said, what I think is happening is that the imap server is async, and you’re not waiting for it to authenticate you before sending the select command – that’s why the error is coming back before the login result in your output

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.