1

Currently im using C# and Microsoft.Office.Interop.Outlook to access my email, i want to filter the mesagges with current date, however the restriction is only retrieving some emails and not all of them, whats wrong with the restriction? This is my code:

 Microsoft.Office.Interop.Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
 DateTime current = DateTime.Now;
 String filter = "";
 var f =ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
 var items = f.Items;
 filter = " [ReceivedTime] >= " + "'"+current.ToString("d")+"'";//Filter 
 var filteredFolder = items.Restrict(filter);
 Console.WriteLine("Emails from today: " + filteredFolder.Count);

That last line is printing only 2 when i have received 5 emails today.

Thanks!

  • Let me know in comments here if the military time format in the duplicate does **not** resolve the problem. – Jeremy Thompson Aug 24 '17 at 00:39
  • 1
    Hi, Thank you for your quick response! The duplicate helped me on my request. I fixed the problem by changing this line: filter = " [ReceivedTime] >= " + "'"+current.ToString("MM/dd/yyyy 00:00)+"'";//Filter Setting the Hour in 00:00 Thanks a lot! – Fabricio Robles Aug 24 '17 at 16:18
  • Thank you @FabricioRobles - I've been searching for that for awhile!!! – Danimal111 Mar 05 '18 at 23:57

0 Answers0