0

I want to use something like the following to manipulate outlook in python, which seems to work for other people. When I type 'win32', 'dispatch' comes up in the dropdown as an available function. But 'GetNameSpace' and 'Create Item' don't appear in the dropdown - why?

I've had the same problem in other projects and it always ends up being a sticking point. Have I just not set up the module correctly?

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
outlookNS = outlook.GetNameSpace("MAPI")
mail = outlook.CreateItem(0)
mail.To = 'To address'
mail.Subject = 'Message subject'
mail.Body = 'Message body'

mail.Send()

Note that I am using Spyder, Python 3.9. Thank you

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • In COM terms it is likely the difference early and late binding. This SO question/answer explores the topic: https://stackoverflow.com/questions/50127959/win32-dispatch-vs-win32-gencache-in-python-what-are-the-pros-and-cons Try instead calling `outlook=win32.gencache.EnsureDispatch(…)` instead. This has the added advantage of also generating all the constants that Outlook uses. – DS_London Dec 30 '21 at 18:18
  • It seems you need to use early binding in the code. The [Automating Outlook from a Visual Basic Application](https://learn.microsoft.com/en-us/office/vba/outlook/concepts/getting-started/automating-outlook-from-a-visual-basic-application) article explains early and late binding technologies. The question is common for all kind of COM-based applications, not only Outlook. – Eugene Astafiev Dec 30 '21 at 23:09

0 Answers0