[Tutor] Problem

Jeff Shannon jeff@ccvcorp.com
Fri Aug 1 19:09:01 2003


Vijayram Gopu wrote:

> Hello,
>  
>  I want to write a script which should do the following things:
>  
> - Read email address from a file and place it in the To address bar.
> - Print Hello in the Subject bar.
> - Access a file from a directory and attach it to th email.
> - Read a text file and copy the message in the text file and copy it 
> in the message area of the email.
> - Save it in the outlook box.
>  
> The outlook box then sends over the email to the email address specified.
>  
> Can I achieve these using Python scripting.. If yes how can we achieve 
> it... I am very new to Python language.. practically know nothing 
> about its syntax etc.


If you need to get Outlook to send an email, then you'll need to look 
into PythonCOM.  Outlook can be loaded as a COM server and given 
instructions -- this is how VB/VBscript control Outlook (and many other 
applications, including the entire Office suite).  You'll need to look 
through the documentation for PythonCOM, which is part of the win32all 
package.  I'd also recommend trying to get your hands on a copy of 
"Python Programming on Win32", by Marc Hammond & Andy Robinson.  It has 
lots of examples of COM and Office scripting.  For specifics on how to 
direct Outlook, you'll need to look at the Visual Basic Help included 
with Outlook itself.  That will tell you how to control Outlook from VB; 
you'll need to translate this to Python yourself, but it's mostly 
straightforward (and the gotchas are discussed in the aforementioned book).

On the other hand, if you just need to assemble & send email, it's 
probably simpler to "roll your own" than it is to control Outlook, 
thanks to Python's "batteries included" library.  With the email package 
and the smtplib module, it's fairly straightforward to create & send email.

Jeff Shannon
Technician/Programmer
Credit International