How to read eml file in python?

前端 未结 4 1415
滥情空心
滥情空心 2021-01-31 12:37

I do not known how to load a eml file in python 3.4.
I want to list all and read all of them in python.

\"ente

4条回答
  •  既然无缘
    2021-01-31 12:59

    I found this code much simpler

    import email
    import os
    
    path = './'
    listing = os.listdir(path)
    
    for fle in listing:
        if str.lower(fle[-3:])=="eml":
            msg = email.message_from_file(open(fle))
            attachments=msg.get_payload()
            for attachment in attachments:
                try:
                    fnam=attachment.get_filename()
                    f=open(fnam, 'wb').write(attachment.get_payload(decode=True,))
                    f.close()
                except Exception as detail:
                    #print detail
                    pass
    

提交回复
热议问题