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

    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.util.*;
    import javax.mail.*; 
    public class ReadMail { 
      public static void main(String args[]) throws Exception { 
      String host = "";
      String user = "";
      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.;
      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) {

    Java Code:
    Exception in thread "main" javax.mail.MessagingException: Connection refused: connect;
      nested exception is: Connection refused: connect
    	at com.sun.mail.imap.IMAPStore.protocolConnect(
    	at javax.mail.Service.connect(
    	at javax.mail.Service.connect(
    	at AddressBook.ReadMail.main(
    Caused by: Connection refused: connect
    	at Method)
    	at com.sun.mail.util.SocketFetcher.createSocket(
    	at com.sun.mail.util.SocketFetcher.getSocket(
    	at com.sun.mail.iap.Protocol.<init>(
    	at com.sun.mail.imap.protocol.IMAPProtocol.<init>(
    	at com.sun.mail.imap.IMAPStore.protocolConnect(
    	... 3 more

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

    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