472,353 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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.
Oct 3 '08 #1
3 3825
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:

http://mail.python.org/pipermail/pyt...ly/007857.html

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

http://mail.python.org/mailman/listinfo/python-win32

Mike
Oct 3 '08 #2
Beliavsky wrote in news:d579f554-be4b-4066-acec-49a7bafb1046
@t41g2000hsc.googlegroups.com in comp.lang.python:
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().strftime( '"%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_from_string(data[0][1])

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

imap.close()
imap.logout()

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Oct 3 '08 #3
On Oct 3, 4:10*pm, Rob Williscroft <r...@freenet.co.ukwrote:
Beliavsky wrote in news:d579f554-be4b-4066-acec-49a7bafb1046
@t41g2000hsc.googlegroups.com in comp.lang.python:
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().strftime( '"%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_from_string(data[0][1])

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

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
Oct 3 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: christof hoeke | last post by:
hi, i wrote a small application which extracts a javadoc similar documentation for xslt stylesheets using python, xslt and pyana. using non-ascii...
1
by: webworldL | last post by:
Has anybody had any luck processing XHTML1.1 documents with xml.sax? Whenever I try it, python loads the W3C DTD from the top, then crashes saying...
6
by: Newbie | last post by:
I am doing some robotics projects but my main area of interest is trying out several algorithms for the processing of the stream of data coming...
3
by: anthony hornby | last post by:
Hi, I am starting my honours degree project and part of it is going to be manipulating ASCII encoded XML files from a legacy database and...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and...
1
by: ankit | last post by:
There are various packages availaible for XML processing using python. So which to choose and when. I summarized some of the features, advantages...
3
by: domtam | last post by:
Hi all, Here is what I want: when a user clicks a <asp:button>, its event handler will do some server-side processing and then pop up a windows...
7
by: pdr14 | last post by:
If I un-comment any line in this program below the line where I commented " all OK up to this point " This program locks up my computer. Windows...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.