Python 当我尝试访问 MailItem COM 中任何与日期相关的字段时崩溃
Python Crashes when I am trying to access any date related fields in MailItem COM
我正在尝试使用 win32com 从 Outlook 打印电子邮件。唯一的问题是,当我尝试访问 MailItem.SentOn
或 MailItem.ReceivedTime
时,Python 崩溃,windows 显示 "Python has stopped working" 对话框 window。这个问题的原因可能是什么?
这是我的代码:
import win32com
import win32com.client
import os
import sys
import re
from datetime import datetime
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
accounts = win32com.client.Dispatch("Outlook.Application").Session.Accounts
inbox = outlook.Folders(accounts[0].DeliveryStore.DisplayName)
folders = inbox.Folders
inbox_messages = folders("Inbox").Items
msg = inbox_messages.GetFirst()
while msg:
print(msg.SenderEmailAddress)
print(msg.Subject)
print (msg.SentOn)
msg = inbox_messages.GetNext()
我在 Windows 10 上使用 Office 365 和 Python 3.7.0。
Error Window
因此并非所有邮件都有 SenderEmailAddress 和 SentOn。
我在我的收件箱上试过你的程序,它似乎在 outlook 生成的邮件上崩溃了 - outlook 生成的无法投递的邮件:
Your message to xxxx@xxxx.com couldn't be delivered.
A custom mail flow rule created by an admin at xxx.onmicrosoft.com has blocked your message.
.
Traceback (most recent call last):
File "xxxx\outl.py", line 24, in <module>
print (msg.SentOn)
File "xxx\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: GetNext.SentOn
不确定为什么它会崩溃 python 对我来说是堆栈崩溃,但我认为你应该处理属性可能丢失的情况。
我也有同样的问题。我的脚本在 Python 3.6.5 中运行良好,但在 3.7.0
中运行失败
我正在尝试使用 win32com 从 Outlook 打印电子邮件。唯一的问题是,当我尝试访问 MailItem.SentOn
或 MailItem.ReceivedTime
时,Python 崩溃,windows 显示 "Python has stopped working" 对话框 window。这个问题的原因可能是什么?
这是我的代码:
import win32com
import win32com.client
import os
import sys
import re
from datetime import datetime
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
accounts = win32com.client.Dispatch("Outlook.Application").Session.Accounts
inbox = outlook.Folders(accounts[0].DeliveryStore.DisplayName)
folders = inbox.Folders
inbox_messages = folders("Inbox").Items
msg = inbox_messages.GetFirst()
while msg:
print(msg.SenderEmailAddress)
print(msg.Subject)
print (msg.SentOn)
msg = inbox_messages.GetNext()
我在 Windows 10 上使用 Office 365 和 Python 3.7.0。
Error Window
因此并非所有邮件都有 SenderEmailAddress 和 SentOn。 我在我的收件箱上试过你的程序,它似乎在 outlook 生成的邮件上崩溃了 - outlook 生成的无法投递的邮件:
Your message to xxxx@xxxx.com couldn't be delivered.
A custom mail flow rule created by an admin at xxx.onmicrosoft.com has blocked your message.
.
Traceback (most recent call last):
File "xxxx\outl.py", line 24, in <module>
print (msg.SentOn)
File "xxx\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: GetNext.SentOn
不确定为什么它会崩溃 python 对我来说是堆栈崩溃,但我认为你应该处理属性可能丢失的情况。
我也有同样的问题。我的脚本在 Python 3.6.5 中运行良好,但在 3.7.0
中运行失败