Problem automating outlook with python

xWestler NoThanks at ^*^#*&%.com
Fri Aug 23 19:21:34 CEST 2002


I'm brand new to python and I thought I'd try to duplicate a VBScript 
I've been using to email documents using outlook.

This code produces a COM exception at the point the attachment is added.

here's the code:

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
message = outlook.CreateItem(0)
message.Recipients.Add("me at example.com")
message.Subject = "Message from Python"
message.Body = "Message Body Text"
message.Attachments.add("c:\Test.txt")
message.Send()

Here's the exception:

com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft 
Outlook', 'Cannot add the attachment; no data source was provided.', 
None, 0, -2147352567), None)

Without that line the email is sent successfully (you have to use a real 
address)

Any ideas or better sample code I can use?

This is under Windows XP Pro, Outlook 98, Python 2.2 (from ActiveState) 
and PythonWin.

If you can provide some insight, thanks!



More information about the Python-list mailing list