My code is not reading all emails from inbox

Viewed 161

I am reading all emails from my inbox through python code as below:

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
for msg in messages :`enter code here`
    print(msg.Subject)

But it is skipping few emails in between the mails. Please help.

1 Answers

The order in which subjects are printed can be different from the view in Outlook. The sorting filter in the view can be retrieved by using the View object from the Outlook object model.

To obtain a View object for the view of the current Explorer, use Explorer.CurrentView instead of the CurrentView property of the current Folder object returned by Explorer.CurrentFolder.

The View object allows you to create customizable views that allow you to better sort, group and ultimately view data of all different types. There are a variety of different view types that provide the flexibility needed to create and maintain your important data.

  • The table view type (olTableView) allows you to view data in a simple field-based table.
  • The Calendar view type (olCalendarView) allows you to view data in a calendar format.
  • The card view type (olCardView) allows you to view data in a series of cards. Each card displays the information contained by the item and can be sorted.
  • The icon view type (olIconView) allows you to view data as icons, similar to a Windows folder or explorer.
  • The timeline view type (olTimelineView) allows you to view data as it is received in a customizable linear time line.

Views are defined and customized using the View object's XML property. The XML property allows you to create and set a customized XML schema that defines the various features of a view.

Related