Python Win32 无法读取 Outlook 电子邮件正文 [英] Python Win32 can't read outlook email body's
问题描述
我正在尝试使用 python 的 win32 模块并获取我的电子邮件的正文.但是,每当我尝试获取它时,我都会收到我尝试获取的任何电子邮件正文的错误.我能够获得消息主题/接收时间/等,但我似乎无法获得正文.
Im trying to use win32 module for python and get the body of my email message. However whenever I try to get it i get an error for any email body I try to get. I am able to get the message subject/timerecieved/etc however I just can't seem to get the body.
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
<ipython-input-41-bdd6c5734297> in <module>()
1 messages = inbox.Items
2 message = messages.GetLast()
----> 3 body_content = message.body#.encode('ascii', 'ignore').decode('ascii')
4 #print (body_content)
C:\Users\e659383\Documents\portableapps\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\win32com\client\dynamic.py in __getattr__(self, attr)
509 debug_attr_print("Getting property Id 0x%x from OLE object" % retEntry.dispid)
510 try:
--> 511 ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
512 except pythoncom.com_error as details:
513 if details.hresult in ERRORS_BAD_CONTEXT:
com_error: (-2147467259, 'Unspecified error', None, None)
我尝试获取正文的任何电子邮件都收到相同的错误.
I get same error for any email message I try to get the body.
推荐答案
不是 100% 肯定,但也许 body 应该使用大写 B,因为它似乎引用了 C# 属性.
Not 100% sure, but perhaps body should use a capital B as it seems to be referencing a C# property.
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.body.aspx
所以:body_content = message.Body
这篇关于Python Win32 无法读取 Outlook 电子邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!