Results 1 to 3 of 3
  1. #1
    Basit56 is offline Member
    Join Date
    Aug 2009
    Rep Power

    Unhappy Facing problem in making connection to mail server

    Hope you all will be fine. I have a server whose IP is and whose name is On this server i have an email server named sendmail. Now i want to connect to this server but the problem is HOW?. I have already wrote a program that connect with gmail and it works fine.
    I have a local user account on my linux server named masood, since my server name is therefore masood email address become Now i want to connect to this account and want to read emails. The problem is what host name and username and password i use. In case of gmail it's simply and your gmail user account and password. But here what i use for host. I also discussed it on linux forum and he replied your servername and mailserver name are same and where you use ""( it with your mail server name. I tried but it gives me error I tried all possible combinations for host name with pop or without pop. It's a starting portion of my code. Please help.

    Java Code:
      public static void main(String[] args) {
            String host = ""; //also tried and and
            String username = "";
            String password = "xxx";
            //String port = "465";
            Scanner scanner = new Scanner(;
            //Create empty properties
            Properties props = new Properties();
             //props.put("", host);
            //Get Session
            Session session = Session.getDefaultInstance(props, null);
            //Get the store
                Store store = session.getStore("pop3");
                System.out.println("Trying to connect host");
                store.connect(host, username, password);
                System.out.println("Connection Successful");
                //Get Folder
                Folder folder = store.getFolder("Inbox");
    and the errors are
    Trying to connect host
    javax.mail.MessagingException: Connect failed;
    nested exception is: Connect failed
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3St
    at javax.mail.Service.connect(
    at javax.mail.Service.connect(
    at GetMessageExample.main(
    Caused by: Connect failed
    at com.sun.mail.pop3.Protocol.<init>( 3)
    at com.sun.mail.pop3.POP3Store.getPort( :227)
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3St
    ... 3 more
    BUILD SUCCESSFUL (total time: 22 seconds)
    Line 28 is store.connect(host, username, password);
    Please help.

    Thank you
    Last edited by Basit56; 01-22-2010 at 03:01 PM.

  2. #2
    FON is offline Senior Member
    Join Date
    Dec 2009
    Belgrade, Serbia
    Rep Power


    Hello Basit56,

    I cannot help you directly
    but here are some hints that could clear up a few thing for you:

    Always this line in your code for debug:

    //Get Session
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(true); // Verbose!

    Using this, u can see in your console how your client and pop3 server
    communicate and exchange messages on this protocol

    Every server offers some commands.
    Try to connect form Telnet and see what servers offer.

    Send some mail to your e-mail and
    try to get it using Telnet - it IS very simple:

    artran ltd | useful tips

    good luck!

  3. #3
    FON is offline Senior Member
    Join Date
    Dec 2009
    Belgrade, Serbia
    Rep Power


    This is from JAVAMAIL API - SUN

    Q: How do I debug problems connecting to my mail server?

    A: The first thing to do when debugging such problems is to determine whether it's a Java problem or a networking problem. Use telnet to try to connect to the remote system. For example, if you're having trouble connecting to the POP3 server named, you would use:

    telnet 110
    If you get a greeting banner you can simply disconnect. If this works, your networking, name service, firewall, etc. are all set up correctly and your problem is most likely in your Java program.

    If it doesn't work, you'll need to check your networking configuration or talk to your network administrator for help. Sometimes a firewall installed on your local machine or on your network will prevent you from connecting to the server. If telnet complains that it doesn't know the host name that you're using, most likely your name service (e.g., DNS) isn't properly configured to resolve internet host names. None of these problems are JavaMail or Java problems.

    Usually, when you get a low level SocketException when connecting, the problem is due to your networking configuration. Usually it's not a Java problem.

Similar Threads

  1. problem with sending mail usin javaX.mail api
    By sandeepsai39 in forum New To Java
    Replies: 4
    Last Post: 11-25-2009, 06:37 AM
  2. i am facing some problem with <h:selectOneMenu> default One
    By sridharavulapati in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 09-09-2009, 03:08 PM
  3. Facing problem while sending e-mail
    By jay8186 in forum Java Servlet
    Replies: 1
    Last Post: 03-25-2009, 08:34 AM
  4. Sql server connection problem
    By tanvirtonu in forum JDBC
    Replies: 1
    Last Post: 03-31-2008, 01:46 PM
  5. java mail server
    By krismedia in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 05:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts