Free Support Forum - aspose.com

Timeout issue in Imap


#1

Hi Team,

I have purchased the licence version of ASPOSE

I am facing the following issue, Please provide me the solution or alternative code for the same

Actually I have one yahoo account and want to fetch emails from inbox folder.

In my inbox folder , there are thousands of mails. I am using the following code

ImapClient imapclient = null;

imapclient = new ImapClient(“imap.mail.yahoo.com”, 993, uName, passText,SecurityOptions.Auto);

imapclient.setConnectionTimeout(25000);

ImapFolderInfoCollection coll = imapclient.listFolders(true);
imapclient.setSecurityOptions(SecurityOptions.Auto);

imapclient.setTimeout(500000);

imapclient.setConnectionTimeout(500000);

imapclient.selectFolder(“Inbox”); //Giving me timeout error

Thanks and Regards,
Ajay Kumar


#2

@ajaykumar2018,

Thank you for contacting Aspose Support.

Please share the complete stack trace and exception message generated using the latest version of Aspose.Email API so that we can investigate this scenario further.


#3

Hi, Thanks for the quick response.

I have tried the above code with new Aspose Jar , now the issue is not coming but some code is depreciated as per new JAR.

Earlier I was using the following code

ImapPageInfo pageInfo = imapclient.listMessagesByPage(500);

but now this code is giving me warning. Please provide me the latest code , My requirement is to fetch messages in a loop means 500 messages at one time.


#4

@ajaykumar2018,

Thank you for your query.

You can use the code snippet given below to fetch messages by page.

imapclient.listMessagesByPage(int itemsPerPage, int pageOffset, PageSettings settings)

We hope that this answered your question. Please feel free to reach us if additional information is required.


#5

thanks. will you please share the full code or just provide me the link where this code is written. Actually my requirement is to get the content in a loop, first 100 then next 100 and so on


#6

@ajaykumar2018,

Please use the code snippet given below to fetch emails by page in a loop.

ImapMessageInfoCollection messageCollection = imapClient.listMessages();
int totalMessages = messageCollection.size();
int messagesPerPage = 100;

int totalPages = (int) ceil((double) totalMessages/(double) messagesPerPage);

for(int i=1;i<=totalPages;i++){
    ImapPageInfo pageInfo = imapClient.listMessagesByPage(messagesPerPage, i-1, new PageSettings());
    ImapMessageInfoCollection messagePageCollection = pageInfo.getItems();

    for(ImapMessageInfo info : messagePageCollection){
        System.out.println("Subject: " + info.getSubject());
    }
}

Please feel free to reach us if additional information is required.


#7

Hi Team,

I am still facing some major issue, this seems to be issue with your DLL

Let me explain you.

I am using the following code

imapclient.selectFolder(“Admin”);
imapclient.setSecurityOptions(SecurityOptions.Auto);
int messagesPerPage = 100;
for(int i=1;i<=100;i++)
{
ImapPageInfo pageInfo = imapclient.listMessagesByPage(messagesPerPage,1, new PageSettings());
ImapMessageInfoCollection collection = pageInfo.getItems();
System.out.println(collection.size());
}

Now the issue in that in Admin folder there are only 2 items. So in the first time it correctly shows the size
But in second time also, when PageNumber is 2 , it still show the size equals to 1
And consequently for every page it shows the size equal to 1 where as it should show 0

Please provide me the solution ASAP as I got stuck from the past many days.

Thanks and Regards,

Ajay Kumar


#8

@ajaykumar2018,

We were able to reproduce the issue that you mentioned. It happens because listMessagesByPage retrieves the last email even if the page does not exist. Therefore, we have logged a ticket in our issue tracking system as EMAILJAVA-34476 to investigate the scenario further. We will update you here as soon as additional information is available.

To overcome the count issue, You should limit the number of iterations in the code by calculating the total number of pages as shown below.

ImapMessageInfoCollection messageCollection = imapClient.listMessages();
int totalMessages = messageCollection.size();
int messagesPerPage = 100;

int totalPages = (int) ceil((double) totalMessages/(double) messagesPerPage);

for(int i=1;i<=totalPages;i++){
    ImapPageInfo pageInfo = imapClient.listMessagesByPage(messagesPerPage, i-1, new PageSettings());
    ImapMessageInfoCollection messagePageCollection = pageInfo.getItems();

    for(ImapMessageInfo info : messagePageCollection){
        System.out.println("Subject: " + info.getSubject());
    }
}

You can also check whether the current page is the last page and break the loop by using the code snippet given below.

// You can use this
System.out.println(pageInfo.getNextPage()); // Will return null if the current page is the last page.
// Or you can use this
System.out.println(pageInfo.getLastPage()); // Will return true if the current page is the last page.

#9

The issues you have found earlier (filed as EMAILJAVA-34476) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by muhammadahmad