Nope, I've checked with my exchange admin, both pop3 and imap are running on their default ports.
Main Topics
Browse All TopicsHi Experts!
I'm trying to write a java program to read emails from our company's exchange server. I've written similar programs before accessing a pop3 account, but I'm having problems accessing my email on the exchange server using the same technique. I understand that the Exchange server doesn't (by default anyway) use pop3, so I've tried using imap, but unsuccessfully. Below is my code (its modeled on one of the javamail tutorials). I've tried using different account name combinations ie. DMAIN_NAME\account_name etc. But nothing seems to work. the error message I keep getting is (I've turned session debugging on):
DEBUG: setDebug: JavaMail version 1.3
DEBUG: getProvider() returning javax.mail.Provider[STORE,
javax.mail.MessagingExcept
nested exception is:
java.net.ConnectException:
at com.sun.mail.imap.IMAPStor
at javax.mail.Service.connect
at javax.mail.Service.connect
at au.com.covermore.EmailRead
at au.com.covermore.EmailRead
The code:
/**
* @author leiberov
* this program is intended to retrieve and parse emails sent by the ashop
* application, the information extracted from the emails is to be stored
* in an xml or text file to be analised and reported from later
*/
package au.com.covermore;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.Intern
public class EmailReader {
/* variables */
/**
* @param args
* popServer - the url of the POP3 server eg. pop.iprimus.com.au
* popUser - POP server user name
* popPassword - password associated with the above username
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
try
{
String popServer=args[0];
String popUser=args[1];
String popPassword=args[2];
System.out.println("java EmailReader "
+ popServer + " " + popUser + " " + popPassword);
receive(popServer, popUser, popPassword);
}
catch (Exception ex)
{
System.out.println("Usage:
+" popServer popUser popPassword");
}
System.exit(0);
}
/**
* this method will retrieve and read the emails from the INBOX
* @param popServer
* @param popUser
* @param popPassword
*/
public static void receive(String popServer, String popUser, String popPassword)
{
Store store=null;
Folder folder=null;
try
{
// -- Get hold of the default session --
Properties props = System.getProperties();
Session session = Session.getDefaultInstance
session.setDebug(true);
// -- Get hold of a POP3 message store, and connect to it --
//store = session.getStore("pop3");
store = session.getStore("imap");
store.connect(popServer, popUser, popPassword);
// -- Try to get hold of the default folder --
folder = store.getDefaultFolder();
if (folder == null) throw new Exception("No default folder");
// -- ...and its INBOX --
folder = folder.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");
// -- Open the folder for read only --
folder.open(Folder.READ_ON
// -- Get the message wrappers and process them --
Message[] msgs = folder.getMessages();
System.out.println("ava au.com.covermore.EmailRead
+" msgs " + msgs.length);
for (int msgNum = 0; msgNum < msgs.length; msgNum++)
{
printMessage(msgs[msgNum])
//processMessage(msgs[msgN
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
// -- Close down nicely --
try
{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}
catch (Exception ex2) {ex2.printStackTrace();}
}
}
/**
* this method will print the message
* @param message
*/
public static void printMessage(Message message)
{
try
{
// Get the header information
String from=((InternetAddress)mes
if (from==null) from=((InternetAddress)mes
System.out.println("FROM: "+from);
String subject=message.getSubject
System.out.println("SUBJEC
//String dateTime = message.getSentDate().toSt
System.out.println("DATE: "+ message.getSentDate());
// -- Get the message part (i.e. the message itself) --
Part messagePart=message;
Object content=messagePart.getCon
// -- or its first body part if it is a multipart message --
if (content instanceof Multipart)
{
messagePart=((Multipart)co
System.out.println("[ Multipart Message ]");
}
// -- Get the content type --
String contentType=messagePart.ge
// -- If the content is plain text, we can print it --
System.out.println("CONTEN
if (contentType.startsWith("t
{
InputStream is = messagePart.getInputStream
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String thisLine=reader.readLine()
while (thisLine!=null)
{
System.out.println(thisLin
thisLine=reader.readLine()
}
}
System.out.println("------
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
/**
* this method will process an email message and write
* relevant contents into the xml file
* @param message
*/
private static void processMessage(Message message)
{
try
{
// -- Get the message part (i.e. the message itself) --
Part messagePart=message;
Object content=messagePart.getCon
// -- or its first body part if it is a multipart message --
if (content instanceof Multipart)
{
messagePart=((Multipart)co
}
// -- Get the content type --
String contentType=messagePart.ge
if (contentType.startsWith("t
{
InputStream is = messagePart.getInputStream
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// now read the message into a List - each message line is a list item
// a List will be easier to manipulate and its indexed
// remove blank lines at the same time
List msgList = new LinkedList();
String thisLine=reader.readLine()
while (thisLine!=null)
{
if(thisLine.trim().length(
msgList.add(thisLine);
thisLine=reader.readLine()
}
}
}
catch(Exception x)
{
x.printStackTrace();
}
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
No, I couldn't telnet into the server using 143 or 110 (default pop3 port). I can however use exchange webmail functionality from my pc on local network (http://serverIPaddress/Ex
How do I enable access to the IMAP or POP3 ports on the exchange server from my client machine?
Business Accounts
Answer for Membership
by: Ajay-SinghPosted on 2007-03-25 at 21:12:38ID: 18790671
sounds to me that popserver is not available on the port mentioned