用Python在Outlook上打印电子邮件
我一直在尝试通过一段时间在Outlook收到的电子邮件打印电子邮件的正文,但是我有以下错误:
Traceback (most recent call last):
File "c:\Users\RMBORGE\Desktop\PythonLib\tempCodeRunnerFile.python", line 10, in <module>
print(message.body)
File "C:\Users\RMBORGE\AppData\Roaming\Python\Python39\site-packages\win32com\client\dynamic.py", line 543, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)
有人可以帮助我吗?
请在下面查看我的代码:
from email import message
import email
import win32com.client as client
outlook = client.Dispatch('Outlook.Application').GetNameSpace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
print(message.body)
I've been trying to print the email's body from the emails that I receive in Outlook for a while, but I'm having the following error:
Traceback (most recent call last):
File "c:\Users\RMBORGE\Desktop\PythonLib\tempCodeRunnerFile.python", line 10, in <module>
print(message.body)
File "C:\Users\RMBORGE\AppData\Roaming\Python\Python39\site-packages\win32com\client\dynamic.py", line 543, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)
Could someone help me?
Please see my code below:
from email import message
import email
import win32com.client as client
outlook = client.Dispatch('Outlook.Application').GetNameSpace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
print(message.body)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,Outlook文件夹可能包含不同类型的项目 - 邮件,文档,注释等您处理邮件项目以及所选项目所需的属性。
请参阅 /a>有关更多信息。
另一个可能的原因是Outlook对象模型中的安全触发器。在 Outlook对象模型安全警告文章。避免此类触发器的可能路由是:
Please remember that Outlook folders may contain different kind of items - mails, documents, notes and etc. Before accessing any properties specific to a particular item type I'd recommend checking the
MessageClass
property first to make sure that you deal with a mail item and the required property exists for the item chosen.See How to determine type of an outlook item in python for more information.
Another possible reason is security triggers in the Outlook object model. Read more about that in the Outlook Object Model Security Warnings article. Possible routes to avoid such triggers are: