Python get Outlook export eml files in the attachment code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.