Hi team,
I am reading the mail using the below code. What is the issue is after this code I am storing some details into my database. But some time above code will read my mail from the IMAP but does not store anything and sometimes it will be stored in my database. I am also capturing errors if any but there is no error occurred. Can you please let me know why some time below code show mail to read in outlook but nothing coming to C# level?
Note: below code is running in task scheduler for every 1 min. And I am only starting the next run only once first will finish.
MailRepository rep = new MailRepository(setting.HostName, setting.Port, true, setting.UserName, setting.Password);
var unreadEmails =GetUnreadMails("inbox/iSourcingiContractApprovalLogic").ToList();
public IEnumerable<Message> GetUnreadMails(string mailBox)
{
return GetMails(mailBox, "UNSEEN").Cast<Message>();
}
private MessageCollection GetMails(string mailBox, string searchPhrase)
{
Mailbox mails = Client.SelectMailbox(mailBox);
MessageCollection messages = mails.SearchParse(searchPhrase);
return messages;
}