Search code examples
pythonoutlookmapi

Not able to get mails from a certain folder in outlook in the order of their received date


python

outlook=win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder=outlook.Folders.Item("required folder")
mails=folder.Items
mail=mails.GetLast()
while(mail):
   print(mail.SentOn)
   mail=mails.GetPrevious()

not getting the mails in the order of their received date

output:

2019-10-27 07:54:44+00:00
2019-10-27 07:55:46+00:00
2019-10-25 14:17:07+00:00
2019-10-23 10:06:08+00:00
2019-10-24 09:33:07+00:00
2019-10-25 02:59:24+00:00

why the output is not in the order of their received date? while the mails in the outlook are in the order of their received date.


Solution

  • There is no order unless you explicitly call Items.Sort. Most likely you will get the items in their creation date, but it is not guaranteed.