运行 进入错误 <unknown>.SaveAsFile,尚未找到通过任何非令牌源从企业 Outlook 中提取文件的解决方案
Running into error <unknown>.SaveAsFile, no solution yet found via any non-token sources for extracting files from enterprise outlook
我创建了程序的下一部分以从我的活动 outlook 中提取特定附件:
import win32com.client as win32
import win32com
from tabulate import tabulate
import os
def findFolder(folderName, searchIn):
try:
lowerAccount = searchIn.Folders
for x in lowerAccount:
if x.Name == folderName:
objective = x
return objective
return None
except Exception as error:
print("Looks like we had an issue accessing the searchIn object")
print(error)
return None
outlook = win32com.client.Dispatch("Outlook.Application")
ons = outlook.GetNamespace("MAPI")
one = 'email@email.nl'
Folder1 = findFolder(one, ons)
inbox = findFolder('Postvak IN', Folder1)
messages=inbox.Items
ma = [["Subject", "Sender", "Attachment", "Saved?"]]
PathName = "C:\Temp\CV_BU_SQ"
os.chdir(PathName)
for msg in messages:
if msg.Class == 43 and "TLS NL_Commvault" in msg.SenderName and len(msg.Attachments) == 1:
CV_file = str(msg.Attachments.Item(1))
CV_pf = os.path.join(os.getcwd() + '\' + CV_file)
res = "Yes!"
try:
msg.Attachments.SaveAsFile(os.getcwd() + '\' + CV_file)
except Exception as e:
res = "No, error: " + str(e)
ma.append([msg.Subject[:30], msg.SenderName[:30], CV_file, res])
print(tabulate(ma,headers="firstrow"))
输出为:
Subject Sender Attachment Saved?
------------------------- ---------------- ---------------------------------------------------- -------------------------------
Backup Job Summary Report TLS NL_Commvault Commvault***DagelijkseBackup_2021-07-23-08-00-13.csv No, error: <unknown>.SaveAsFile
或原始错误:
Traceback (most recent call last):
File "C:/Users/id983857/PycharmProjects/CheckCVMail/main.py", line 37, in <module>
msg.Attachments.SaveAsFile(os.getcwd() + '\' + CV_file)
File "C:\Users\id983857\CheckCVMail\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.SaveAsFile
本outlook环境基于Office 365,企业版...
无法测试任何电子邮件提取软件演示版,因为这是企业版。
根据 O365 或 HTML,我不需要令牌来阅读我的邮件,只需要我的用户帐户。
我无权访问非企业 O365。
我想知道这个错误的原因是什么?
SaveAsFile(...) 的任何值都会导致相同的错误。
我希望有人知道如何解决这个问题。
换行
CV_file = str(msg.Attachments.Item(1))
到
CV_file = msg.Attachments.Item(1).FileName
和
msg.Attachments.SaveAsFile(os.getcwd() + '\' + CV_file)
到
msg.Attachments.Item(1).SaveAsFile(os.getcwd() + '\' + CV_file)
Attachments
属性returns附件合集。如果您需要访问集合中的第一个附件,您可以使用 Item
方法:
msg.Attachments.Item(1)
我创建了程序的下一部分以从我的活动 outlook 中提取特定附件:
import win32com.client as win32
import win32com
from tabulate import tabulate
import os
def findFolder(folderName, searchIn):
try:
lowerAccount = searchIn.Folders
for x in lowerAccount:
if x.Name == folderName:
objective = x
return objective
return None
except Exception as error:
print("Looks like we had an issue accessing the searchIn object")
print(error)
return None
outlook = win32com.client.Dispatch("Outlook.Application")
ons = outlook.GetNamespace("MAPI")
one = 'email@email.nl'
Folder1 = findFolder(one, ons)
inbox = findFolder('Postvak IN', Folder1)
messages=inbox.Items
ma = [["Subject", "Sender", "Attachment", "Saved?"]]
PathName = "C:\Temp\CV_BU_SQ"
os.chdir(PathName)
for msg in messages:
if msg.Class == 43 and "TLS NL_Commvault" in msg.SenderName and len(msg.Attachments) == 1:
CV_file = str(msg.Attachments.Item(1))
CV_pf = os.path.join(os.getcwd() + '\' + CV_file)
res = "Yes!"
try:
msg.Attachments.SaveAsFile(os.getcwd() + '\' + CV_file)
except Exception as e:
res = "No, error: " + str(e)
ma.append([msg.Subject[:30], msg.SenderName[:30], CV_file, res])
print(tabulate(ma,headers="firstrow"))
输出为:
Subject Sender Attachment Saved?
------------------------- ---------------- ---------------------------------------------------- -------------------------------
Backup Job Summary Report TLS NL_Commvault Commvault***DagelijkseBackup_2021-07-23-08-00-13.csv No, error: <unknown>.SaveAsFile
或原始错误:
Traceback (most recent call last):
File "C:/Users/id983857/PycharmProjects/CheckCVMail/main.py", line 37, in <module>
msg.Attachments.SaveAsFile(os.getcwd() + '\' + CV_file)
File "C:\Users\id983857\CheckCVMail\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.SaveAsFile
本outlook环境基于Office 365,企业版... 无法测试任何电子邮件提取软件演示版,因为这是企业版。 根据 O365 或 HTML,我不需要令牌来阅读我的邮件,只需要我的用户帐户。 我无权访问非企业 O365。
我想知道这个错误的原因是什么?
SaveAsFile(...) 的任何值都会导致相同的错误。
我希望有人知道如何解决这个问题。
换行
CV_file = str(msg.Attachments.Item(1))
到
CV_file = msg.Attachments.Item(1).FileName
和
msg.Attachments.SaveAsFile(os.getcwd() + '\' + CV_file)
到
msg.Attachments.Item(1).SaveAsFile(os.getcwd() + '\' + CV_file)
Attachments
属性returns附件合集。如果您需要访问集合中的第一个附件,您可以使用 Item
方法:
msg.Attachments.Item(1)