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
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