用Python在Outlook上打印电子邮件

发布于 2025-01-31 17:19:30 字数 806 浏览 4 评论 0原文

我一直在尝试通过一段时间在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城半夏 2025-02-07 17:19:30

请记住,Outlook文件夹可能包含不同类型的项目 - 邮件,文档,注释等您处理邮件项目以及所选项目所需的属性。

请参阅 /a>有关更多信息。

另一个可能的原因是Outlook对象模型中的安全触发器。在 Outlook对象模型安全警告文章。避免此类触发器的可能路由是:

  1. 使用Outlook所基于的低级API - 扩展MAPI。或者只是考虑使用该API周围的任何包装器,例如赎回。
  2. 使用Outlook中打开/关闭安全问题的组件,请参阅 nofollow noreferrer“> Outlook Security Manager
  3. 在处理OOM时,请使用组策略来配置安全问题。
  4. 使用最新数据库安装任何防病毒软件。

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:

  1. Use a low-level API on which Outlook is based on - Extended MAPI. Or just consider using any wrapper around that API such as Redemption.
  2. Use components for turning on/off security issues in Outlook, see Outlook Security Manager.
  3. Use group policy to configure security issues when dealing with OOM.
  4. Install any antivirus software with latest databases.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文