Results 1 to 2 of 2
  1. #1
    j0rdan is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Connecting to a Microsoft exchange server

    Practically i need to read a few e-mails from my Microsoft exchange server.

    I'm guessing its not connecting to my exchange server properly I don't know if its because my email has a different password to my login or because I'm doing something wrong. I'm using a host that I've been able to send messages with but that is using SMTP. So I'm wondering if we have blocked pop3 or imap?

    this is what I have looked into so far and I'm getting this as an error.
    Java Code:
    package AddressBook;
    
    import java.io.*;
    import java.util.*;
    import javax.mail.*; 
    
    public class ReadMail { 
    
      public static void main(String args[]) throws Exception { 
    
      String host = "C000010.example.com";
      String user = "example@example.com";
      String password = "password"; 
    
      // Get system properties 
       Properties properties = System.getProperties(); 
    
      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);
    
      // Get a Store object that implements the specified protocol.
      Store store = session.getStore("imap");
    
      //Connect to the current host using the specified username and password.
      store.connect(host, user, password);
    
      //Create a Folder object corresponding to the given name.
      Folder folder = store.getFolder("inbox");
    
      // Open the Folder.
      folder.open(Folder.READ_ONLY);
    
      Message[] message = folder.getMessages();
    
      // Display message.
      for (int i = 0; i < message.length; i++) {
    
      System.out.println("------------ Message " + (i + 1) + " ------------");
    
      System.out.println("SentDate : " + message[i].getSentDate());
      System.out.println("From : " + message[i].getFrom()[0]);
      System.out.println("Subject : " + message[i].getSubject());
      System.out.print("Message : ");
    
      InputStream stream = message[i].getInputStream();
      while (stream.available() != 0) {
      System.out.print((char) stream.read());
      }
      System.out.println();
      }
    
      folder.close(true);
      store.close();
      }
    }
    error

    Java Code:
    Exception in thread "main" javax.mail.MessagingException: Connection refused: connect;
      nested exception is:
    	java.net.ConnectException: Connection refused: connect
    	at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
    	at javax.mail.Service.connect(Service.java:295)
    	at javax.mail.Service.connect(Service.java:176)
    	at AddressBook.ReadMail.main(ReadMail.java:25)
    Caused by: java.net.ConnectException: Connection refused: connect
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    	at java.net.Socket.connect(Socket.java:529)
    	at java.net.Socket.connect(Socket.java:478)
    	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
    	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
    	at com.sun.mail.iap.Protocol.<init>(Protocol.java:113)
    	at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:111)
    	at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:637)
    	... 3 more

  2. #2
    j0rdan is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: Connecting to a Microsoft exchange server

    any ideas ? if not I'm going to go home this afternoon and try to connect with google as there's quite a few online that link to gmail. But because gmail is blocked internally I'm guessing it wont work on my laptop at work.

Similar Threads

  1. connecting to microsoft outlook server api?
    By j0rdan in forum New To Java
    Replies: 4
    Last Post: 05-25-2012, 03:48 PM
  2. Replies: 6
    Last Post: 12-25-2011, 11:33 PM
  3. Replies: 9
    Last Post: 11-30-2010, 01:25 PM
  4. Replies: 0
    Last Post: 12-16-2008, 08:32 AM
  5. client/server messages exchange after 5 min
    By dim_ath in forum Advanced Java
    Replies: 2
    Last Post: 01-22-2008, 08:46 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
  •