I am trying to automate outlook, using python Django. the code works pretty good directly using python, but when using it in my Django app it gives me this error.
> pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
and my views code is :
import win32com.client as win32
def about(request):
olApp = win32.Dispatch('Outlook.Application')
olNS = olApp.GetNameSpace('MAPI')
inbox = olNS.GetDefaultFolder(6)
messages = inbox.Items
for msg in messages:
if msg.Class==43:
if msg.SenderEmailType=='EX':
print(1,msg.Sender.GetExchangeUser().PrimarySmtpAddress)
else:
print(2, msg.SenderEmailAddress)
return render(request,'Home/About.html')
So any suggestion to solve this problem?