我試着去閱讀電子郵件和附件下載使用win32com模塊在Python我自己的文件夾,我停在獲取安裝對象:如何使用win32com.client在Python中保存來自Outlook的附件?
from win32com.client import Dispatch
import datetime as date
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder("6")
all_inbox = inbox.Items
val_date = date.date.today()
sub_today = 'Hi'
att_today = 'Attachment.xlsx'
for msg in all_inbox:
if msg.Subject == sub_today:
break
for att in msg.Attachments:
if att.FileName == att_today:
break
att.SaveAsFile('new.xlsx')
att.ExtractFile('new.xlsx')
open(att)
att.WriteToFile('x')
最後4行工作的無...
>>> att.ExtractFile('new.xlsx')
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.ExtractFile
>>> open(att)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: coercing to Unicode: need string or buffer, instance found
>>> att.WriteToFile('x')
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.WriteToFile
att.SaveAsFile('new.xlsx')
沒有錯誤,但工作目錄中沒有這樣的文件。似乎該行被忽略...
任何人都可以幫忙嗎?提前致謝!
你現在可以接受你的答案:)。 –