473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Similar topics

1
2541
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 characters was a problem. so i set the defaultending to UTF-8 and now everything works (at least it seems so, need to do more testing though). it may not be the most elegant solution (according...
1
2150
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 that there's an error in the external DTD. All I need to do is rip through a bunch of XHTML documents and extract some data, does anybody know a quick way to do this without sax making outgoing...
6
3396
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 from the video. I am wondering what type of camera I should invest in. Either I could buy a web cam and hope I can find a driver I could either modify or use. i.e. every frame is somehow stored on...
3
1373
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 converting them to Unicode and doing text processing stuff on the data. I am new to python ( total n00b ) but am keen to use it as the rest of the software my application has to extend is already written...
6
4971
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 creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a...
1
1622
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 and disadvantages of some packages int the following text. Have a look to it. May this get out of the dillema of choice. Here we go: OPTIONS ========= - libxml2
3
1750
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 of another page. As far as I know, if no pop-up blocker is disabled, the button event handler can be something like the following to pop-up a window after server-side processing
7
1895
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 task manager will show "Not Responding" for Python in the Applications tab and in the Performance tabe the CPU usage will be locked at %100. I've experienced the same problem on 2 different...
1
3423
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 real-world problem as example. If you don't know elisp, first take a gander at Emacs Lisp Basics. HTML version with links and colors is at: http://xahlee.org/emacs/elisp_text_processing.html
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.