processing email with Python on Windows?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Beliavsky

    processing email with Python on Windows?

    I work for a financial company where we run Windows XP and read email
    using Microsoft Outlook 2003. I get daily files that come as email
    attachments from various counterparties. I save them as h:\firm_name
    \yyyymmdd.csv . Would Python be a good tool to automate the process of
    saving reports, or would it be more convenient to use a Microsoft
    proprietary language such as VB or C#? Of course one factor is one's
    relative competence with the various languages.
  • Mike Driscoll

    #2
    Re: processing email with Python on Windows?

    On Oct 3, 9:01 am, Beliavsky <beliav...@aol. comwrote:
    I work for a financial company where we run Windows XP and read email
    using Microsoft Outlook 2003. I get daily files that come as email
    attachments from various counterparties. I save them as h:\firm_name
    \yyyymmdd.csv . Would Python be a good tool to automate the process of
    saving reports, or would it be more convenient to use a Microsoft
    proprietary language such as VB or C#? Of course one factor is one's
    relative competence with the various languages.
    Python can do it using the PyWin32 package. You'll probably connect to
    it with COM or ctypes and hack at it that way. Do a Google search for
    Python and Outlook and you'll find various ideas, such as the ones at
    this link:



    I recommend giving it a try and if you get stuck, post to the PyWin32
    user's group:



    Mike

    Comment

    • Rob Williscroft

      #3
      Re: processing email with Python on Windows?

      Beliavsky wrote in news:d579f554-be4b-4066-acec-49a7bafb1046
      @t41g2000hsc.go oglegroups.com in comp.lang.pytho n:
      I work for a financial company where we run Windows XP and read email
      using Microsoft Outlook 2003. I get daily files that come as email
      attachments from various counterparties. I save them as h:\firm_name
      \yyyymmdd.csv . Would Python be a good tool to automate the process of
      saving reports, or would it be more convenient to use a Microsoft
      proprietary language such as VB or C#? Of course one factor is one's
      relative competence with the various languages.
      >
      Assuming your Outlook is using Exchange (or at least a IMAP server),
      you can use imaplib in the standard library.

      This example should list the messages and attachments in you InBox
      fot today.

      EXCHANGE = '' #<-- YOUR EXCHANGE SERVER HERE
      EXCHANGE_PORT = 143 # default
      USER = '' #<-- YOUR USERNAME
      PWD ='' #<-- YOUR PASSWORD

      import imaplib, email
      from datetime import date

      today = date.today().st rftime( '"%d-%b-%Y"' )

      imap = imaplib.IMAP4( EXCHANGE, EXCHANGE_PORT )
      imap.login( USER, PWD )
      imap.select( 'InBox' )

      typ, data = imap.search( None, 'SINCE', today )
      for num in data[0].split():
      typ, data = imap.fetch(num, '(RFC822)')
      msg = email.message_f rom_string(data[0][1])

      print ( "%s, %s\n" % ( num, msg['subject'] ) )
      for part in msg.walk():
      if part.get_filena me() is not None:
      print ( " %s\n" % part.get_filena me() )

      imap.close()
      imap.logout()

      Rob.
      --

      Comment

      • Mike Driscoll

        #4
        Re: processing email with Python on Windows?

        On Oct 3, 4:10 pm, Rob Williscroft <r...@freenet.c o.ukwrote:
        Beliavsky wrote in news:d579f554-be4b-4066-acec-49a7bafb1046
        @t41g2000hsc.go oglegroups.com in comp.lang.pytho n:
        >
        I work for a financial company where we run Windows XP and read email
        using Microsoft Outlook 2003. I get daily files that come as email
        attachments from various counterparties. I save them as h:\firm_name
        \yyyymmdd.csv . Would Python be a good tool to automate the process of
        saving reports, or would it be more convenient to use a Microsoft
        proprietary language such as VB or C#? Of course one factor is one's
        relative competence with the various languages.
        >
        Assuming your Outlook is using Exchange (or at least a IMAP server),
        you can use imaplib in the standard library.
        >
        This example should list the messages and attachments in you InBox
        fot today.
        >
        EXCHANGE = '' #<-- YOUR EXCHANGE SERVER HERE
        EXCHANGE_PORT = 143 # default
        USER = '' #<-- YOUR USERNAME
        PWD ='' #<-- YOUR PASSWORD
        >
        import imaplib, email
        from datetime import date
        >
        today = date.today().st rftime( '"%d-%b-%Y"' )
        >
        imap = imaplib.IMAP4( EXCHANGE, EXCHANGE_PORT )
        imap.login( USER, PWD )
        imap.select( 'InBox' )
        >
        typ, data = imap.search( None, 'SINCE', today )
        for num in data[0].split():
          typ, data = imap.fetch(num, '(RFC822)')
          msg = email.message_f rom_string(data[0][1])
        >
          print ( "%s, %s\n" % ( num, msg['subject'] ) )
          for part in msg.walk():
            if part.get_filena me() is not None:
              print ( "  %s\n" % part.get_filena me() )
        >
        imap.close()
        imap.logout()
        >
        Rob.
        --http://www.victim-prime.dsl.pipex .com/
        As I understand it, Exchange has to be configured specifically to
        allow IMAP and POP3, so this method may not work unless his admin has
        allowed it. Good idea though!

        Mike

        Comment

        Working...