0

code hangs forever until close the program for tcp call's and not throwing any exception i have tried reconnection for every email fetch

var client = new Imap4Client();
client.SendTimeout = 180000;
client.ReceiveTimeout = 300000;
client.ConnectSsl(mailServer, port );
client.LoginFast(EmailId, password);

........

try {
    Mailbox mails = client.SelectMailbox(mailBox);
    int Count = mails.MessageCount;

    while (Count > 0 && ControlLoop && client.IsConnected)
    {
        ... disconnect & create new TCP email login 
        FlagCollection fg = mails.Fetch.Flags(Count); // timeout not working
        ActiveUp.Net.Mail.Message msg = mails.Fetch.MessageObject(Count); // timeout not working

        IFlagCollection newfg = fg;
        mails.SetFlags(Count, newfg); // timeout not working
        
        int getuid = mails.Fetch.Uid(Count); // timeout not working
        
       Count--;
       --- ControlLoop  set true for last 6 hour data only 
        ..... save messages in DB
    }
} catch(Exception ex){ 
        .... log error
        }
    ```
  • tried this solution also https://www.codeproject.com/Questions/5270191/Activeup-mailsystem-net-selectmailbox-function-may – Vinayak Walanj Nov 03 '20 at 10:05
  • For additional info, please [edit] your question instead of commenting. – Fildor Nov 03 '20 at 10:06
  • It is normal for TCP to stay open until it is closed. to determine when a message ends you either have to send a byte count at beginning of message or send a terminating character than is not in the message and then on receive end check for the termination. You can implement a Keep-Alive on the Server that checks for idle channel and closes connection when idle. To prevent a Keep-Alive from closing a channel a client can send a message with no data. – jdweng Nov 03 '20 at 10:50

0 Answers0