Reading mail from the server and storing it in the database are two steps. Which step is the problem?
You can use breakpoints to see if you get the expected result after you get the end of reading the mail.
If there is a problem with the first step, you can try this code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("test@outlook.com", "Password");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
Mailbox mb = new Mailbox("test@outlook.com");
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
FindItemsResults<Item> findResults;
ItemView view = new ItemView(100);
do
{
findResults = service.FindItems(WellKnownFolderName.Inbox, sf, view);
foreach (var item in findResults.Items)
{
Console.WriteLine(item.Subject);
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
while (findResults.MoreAvailable);
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.