Background
Leave, the company mailbox is always accessed from the browser, so the mail is not stored locally. If you don't have an attachment, you can open it directly with Word. However, an attachment will open an error.
Also export can only be EML format
In fact, it is the text message, e-mail is also the text.
So it's easy.
Reused the previous code.
#!/usr/bin/env python#encoding=utf-8 "" "Copyright (c) Ekse <[email protected]>all rights reserved." " Import email, osfrom optparse import Optionparser class work: # class to get Attachement def __init__ (self, director y = './'): self.directory = Directory self.body = ' def Getatt (self): # traverse the Directory For root, dirs, files in Os.walk (self.directory): for fl in files:routine = Self.director Y + R ' \ \ ' + FL print routine Filepointer = open (routine, ' R ') # Read file as Email for line in Filepointer:self.body + = line mail = Email.message_fro M_string (Self.body) # Walk the stream, get attachement for part in Mail.walk (): filename = email. Header.decode_header (Part.get_filename ()) [0][0] Att_path = Os.path.join (sel F.directory, filename) outfile = open (Att_path, ' WB ') if part.get_payload (decode = True): Outfile.write (part.get_payload (decode = True)) outfile.close () def main (): # Use Optionparser to privide opt usage = "usage:%prog [options] arg" parser = optionparser (usage) parser.add_opt Ion ("-D", "--dir", dest= "directory", help= "processing directory") opt, args = Parser.parse_a RGS () p = Work (opt.directory) P.getatt () if __name__ = = ' __main__ ': Main ()
Python get Outlook export eml files in the attachment code