Search code examples
pythonoutlookwin32comoffice-automationcom-automation

How to start Outlook with Python and win32com


I manage to open Outlook Elements like mails or task with this code:

import win32com.client as win32

outlook = win32.gencache.EnsureDispatch('Outlook.Application')
new_mail = outlook.CreateItem(4)
new_mail.Display(True)

And its possible to open Excel with this code:

excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible = True

But how can I just open the main window of outlook? Can't find any functions or numbers for the "createItem" to just open the normal outlook window.

Someone got ideas?

I tried to search throu the MS VBA Api but couldnt find any solution


Solution

  • Inspired by this, one option might be:

    outlook.Session.GetDefaultFolder(6).Display()
    

    where 6 corresponds to the inbox as documented here.