0
我使用Python 2.7(新的Python),我試圖挽救電子郵件附件(使用exchangelib),在這裏它工作得很好:FileAttachment的必須有一個帳戶
for attachment in item.attachments:
if isinstance(attachment, FileAttachment):
local_path = os.path.join(filepath, attachment.name)
with open(local_path, 'wb') as f:
f.write(attachment.content)
我的問題是當我嘗試保存添加郵件項目(附加到郵件)的郵件附件時,添加的郵件包含文件。
elif isinstance(attachment, ItemAttachment):
if isinstance(attachment.item, Message):
os.makedirs(filepath+"attachedMail")
attachedmailpath=filepath+"attachedMail/"
new_item=attachment.item
for attachment in new_item.attachments:
if isinstance(attachment, FileAttachment):
local_path=os.path.join(attachedmailpath,attachment.name)
with open(local_path, 'wb') as f:
f.write(attachment.content)
當我運行這段代碼會創建一個與它的名稱的文件,但它並沒有寫在它的問題是在f.write(attachment.content)
的出現的錯誤是:
raise ValueError('%s must have an account' % self.__class__.__name__)
ValueError: FileAttachment must have an account
對不起,我的英語和感謝!
請https://github.com/ecederstrand/exchangelib/issues文件爲這個錯誤應該可以從該被自身添加爲附件的電子郵件附件獲得。 –