Python 2.7 使用Python从Outlook 2010获取附件

Python 2.7 使用Python从Outlook 2010获取附件,python-2.7,outlook-2010,pywin32,win32com,Python 2.7,Outlook 2010,Pywin32,Win32com,我有以下脚本,它正在尝试从Outlook获取附件 outlook = win32com.client.Dispatch("Outlook.Application") inbox = outlook.GetDefaultFolder(0) messages = inbox.Items message = messages.GetLast() #open last message attachments = message.Attachments #assign attachments to att

我有以下脚本,它正在尝试从Outlook获取附件

outlook = win32com.client.Dispatch("Outlook.Application")
inbox = outlook.GetDefaultFolder(0)
messages = inbox.Items
message = messages.GetLast() #open last message
attachments = message.Attachments #assign attachments to attachment variable
attachment = attachments.Item(1)
attachment.SaveASFile(os.path.join('c:', 'temp'))
然而,当我运行它时,我得到以下信息:

Traceback (most recent call last):
File "C:/Users/e003048/QA/trunk/automation/selenium/src/global_functions/util_get_email_attachments.py", line 11, in <module>
inbox = outlook.GetDefaultFolder(0)
File "C:\Python27\Lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: Outlook.Application.GetDefaultFolder

未在应用程序对象上定义
GetDefaultFolder
(请参阅),而是在通过

mapi = outlook.GetNameSpace("MAPI")
然后

我想你也可以用

mapi = outlook.Session

不是在应用程序对象上定义
GetNameSpace

GetDefaultFolder
,而是在通过

mapi = outlook.GetNameSpace("MAPI")
然后

我想你也可以用

mapi = outlook.Session

我没有使用
GetNameSpace

而是尝试了您的建议,并编辑了我的问题,但在执行此操作后出现了第二个错误。@DarthOpto您如何知道0是有效值谢谢,这是有效的,显然收件箱不是0,但是6我尝试了你的建议,编辑了我的问题,出现了第二个错误。@DarthOpto你怎么知道0是有效值谢谢,这是有效的,显然收件箱不是0,而是6
mapi = outlook.Session