0

I want to save attachments from outlook using Python, Attachment from a fixed email subject. I already searched it got an answer that is not working and I cannot comment. - Save using Win32 Outlook

I tried the code and here it is -

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')

Upon Executing it in Command Prompt I get error as -

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
Abhinav Kumar
  • 177
  • 2
  • 5
  • 22

1 Answers1

0

Attachment object in OOM (att variable in your code) does not expose the ExtractFile method. Neither does it expose the WriteToFile method.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78