How to save attachment from outlook using win32com.client in Python?

后端 未结 3 1110
北海茫月
北海茫月 2020-12-09 06:08

Im trying to read email and download the attachment to my own folder using win32com module in Python, I stopped at getting the attachment object:

from win32c         


        
相关标签:
3条回答
  • 2020-12-09 06:26

    if you want to just save the attachment, comment out the last 3 lines and write the entire directory in last 4th line to save at a specific location.

    0 讨论(0)
  • 2020-12-09 06:29

    Just to update, I have solved this issue by claiming both dir and the file name itself in SaveAsFile:

    att.SaveAsFile(os.getcwd() + '\\new.xlsx')
    

    It is not like most threads I've seen here saying that you only need to put path in it. Actually both path and file name are needed.

    Also, weirdly, you have to put os.getcwd() here since Python wouldn't recognize current running dir - in R, after we set working dir with getwd(), we are able to write to any file at this location.

    0 讨论(0)
  • 2020-12-09 06:31

    Where do you think the current working directory is? I'd say you are looking at the wrong folder, SaveAsFile in general works just fine.

    Simply pass a full path to SaveAsFile, that should solve your problem.

    0 讨论(0)
提交回复
热议问题