【发布时间】:2021-06-15 03:32:43
【问题描述】:
我是第一次使用堆栈溢出。我在这里联系是因为我无法使用 python 保存 Outlook 电子邮件 (.MSG)。这个想法是在物理驱动器中存档电子邮件。
一切正常,除了抛出一个非常一般错误的另存为命令。如果有人可以帮助我,那将是很大的帮助。
这是我正在使用的代码:
import win32com.client as win32
from win32com.client import Dispatch
import os
import re
os.chdir("C:\\Users\\username\\Downloads\\RPA")
outlook = win32.gencache.EnsureDispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
print(inbox)
messages = inbox.Items
for message in messages:
message = messages.GetNext()
name = str(message.Subject)
name = re.sub('[^A-Za-z0-9]+', '', name) + '.msg'
print(name)
# message.Display(True)
message.SaveAs(os.getcwd() + '//' + name)
执行代码时遇到的错误
return self._oleobj_.InvokeTypes(61521, LCID, 1, (24, 0), ((8, 1), (12, 17)),Path pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)
【问题讨论】: