JAVAMAIL - IMAP Connection Failure: "* BYE disconnecting"

D

Daniel Albisser

Hi @ll,


I using the Java Mail API to access a mail server over IMAP.

Step-By-Step Program:
1) Get all folders from the IMAP account
- open connection to the store
- accessing mail server and get folder structure
- close connection to the store
2) Get the emails for each account (loop)
- open connection to the store
- open current folder
- accessing mail server and get emails of opened folder
- close current folder
- close connection to the store

Problem:
In the second step the program throws a MessagingException
"* BYE Disonncetion". Some times by the first iteration othertimes
on the seconde and so on.

How I solved that problem (code snippet):
....
int numOfTries = 0;
int MAX_NUM_OF_TRIES = 10;
boolean connected = false;
while(!connected || numOfTries > MAX_NUM_OF_TRIES)
{
try
{
store.connect(
storeInfo.getServerAddress(),
storeInfo.getUsername(),
storeInfo.getPassword());
connected = true;
}
catch (MessagingException e)
{
System.out.println("Connection failed: Number of Try = " + numOfTries);
System.out.println("Exception Message: " + e.getMessage());

numOfTries++;

try
{
Thread.sleep(500);
}
catch (InterruptedException e1)
{
}
}
}
.....

With this code it works, but the mail client has to try connecting 4 times! That
means it takes up to 2 seconds for accesing the system! I think this it is not really
the best solution, it takes ~four times longer to establish a connection to the
server!

Questions:
- Does somebody know that problem and how has he/she solved that?
- Is there another way to solve it?
- This problem lies on the serverside - Is that true?
- Is this a familiar problem of IMAP mail servers?


Thanks a lot for helping!
Greetz,
Dani
 
G

GaryM

Daniel Albisser said:
Questions:
- Does somebody know that problem and how has he/she solved that?
- Is there another way to solve it?
- This problem lies on the serverside - Is that true?
- Is this a familiar problem of IMAP mail servers?


Thanks a lot for helping!
Greetz,
Dani

A couple of pointers that might help.

First put Javamail in debug mode:

props.put("mail.debug", "true");

where props is your Session props. This should
provide a level of detail in the connection process
that might show you how far you are getting.

Second, review the timeouts per the doc here.
Most are infinite, but a few are not:

http://java.sun.com/products/javamail/1.3/docs/javadocs/com/sun/mail/imap/package-summary.html

Lastly repost your question to Sun's Javamail Forum here,
where there are a lot of highly experienced users of this API:

http://forum.java.sun.com/forum.jsp?forum=43

HTH,

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top