我想使用Python从Outlook中保存附件,而从固定电子邮件主题中保存附件。我已经搜索过,得到的答案不起作用,我无法发表评论。 -Save using Win32 Outlook
我尝试了代码,在这里-
from win32com.client import Dispatch
import datetime as date
import os
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder("6")
all_inbox = inbox.Items
val_date = date.date.today()
sub_today = 'Download Attachment 1'
att_today = '1.csv'
for msg in all_inbox:
if msg.Subject == sub_today:
break
for att in msg.Attachments:
if att.FileName == att_today:
break
att.SaveAsFile(os.getcwd() + '\\1.csv')
att.ExtractFile('1.csv')
open(att)
att.WriteToFile('x')
在命令提示符下执行该命令时,出现错误--
D:\r>python attach.py
Traceback (most recent call last):
File "attach.py", line 21, in <module>
att.ExtractFile('1.csv')
File "C:\Program Files\Python37\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.ExtractFile
答案 0 :(得分:0)
Attachment
对象(代码中的att
变量)不会公开ExtractFile方法。它也没有公开WriteToFile方法。