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

  • SEARCH
  • Home
  • 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 8643497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:03:22+00:00 2026-06-12T12:03:22+00:00

I am trying to connect to my gmail inbox to read messages through Java

  • 0

I am trying to connect to my gmail inbox to read messages through Java Application. I am using..

  • jdk1.6.0_13
  • javamail-1.4.3 libs – (mail.jar, mailapi.jar, imap.jar)

Below is my code : MailReader.java

import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;

public class MailReader
{
    public static void main(String[] args)
    {
        readMail();     
    }

    public static void readMail()
    {
        Properties props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        try
        {
            Session session = Session.getDefaultInstance(props, null);
            Store store = session.getStore("imaps");
            store.connect("imap.gmail.com", "myEmailId@gmail.com", "myPwd");
            System.out.println("Store Connected..");

            //inbox = (Folder) store.getFolder("Inbox");
            //inbox.open(Folder.READ_WRITE);
            //Further processing of inbox....
        }
        catch (MessagingException e)
        {
            e.printStackTrace();            
        }
    }
}

I expect to get store connected, but call to store.connect() never returns and I get below output :


javax.mail.MessagingException: Connection timed out;
nested
exception is:
java.net.ConnectException: Connection timed out
at
com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:441)
at
javax.mail.Service.connect(Service.java:233)
at
javax.mail.Service.connect(Service.java:134)
at
ReadMail.readMail(ReadMail.java:21)
at ReadMail.main(ReadMail.java:10)

However I am able to SEND email by Java using SMTP, Transport.send() and same gmail account. But cannot read emails.
What can be the solution ?

  • 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-06-12T12:03:23+00:00Added an answer on June 12, 2026 at 12:03 pm

    IMAP work off a different port (143 for non-secure, 993 for secure) to sendmail (25) and I suspect that’s blocked. Can you telnet on that port to that server e.g.

    telnet imap.gmail.com {port number}
    

    That’ll indicate if you have network connectivity.

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

Sidebar

Related Questions

I am trying to connect to my gmail account using com.sun.mail ..... Mail api.
I am trying to connect to my gmail account via smtp using port 465
I am trying to connect to a MySQL Server using JDBC tool in java
I'm trying to connect to Gmail through IMAP with PHP running in Apache. This
I am trying to read mail from an Imap Server (Gmail). I would check
I am trying to send email through gmail using PHPMailer_V5.1. Getting the following error,
I am trying to connect gmail using C# pop3 but it give an error
I am trying to connect to gmail via its IMAP API . I am
I trying to connect to a Java Service with some special security requirements It
I am trying to connect to a Servlet with my j2me application and it's

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.