Problem automating outlook with python

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


In article <mailman.1030125763.937.python-list at python.org>, 
anthony at computronix.com says...
> Maybe I am missing something obvious, but don't you have to use
> 
> "c:\\test.txt"
> 
> instead of
> 
> "c:\test.txt"?
> 
> or use os.path.join("c:", "test.txt")
> 

The double backslash was a good idea.  I'm embarrassed that I didn't 
think to try it.

Unfortunately neither the double backslash or the os.path.join() made 
any difference.  Exact same COM exception.

As a sanity check I added code to open the file and read it.  After 
playing with various combinations of various slashes, what seemed to 
work for reading the file was "c:/text.txt".  In the code below:

f = open("c:/test.txt", "r")
print f.read()
f.close()
message.Attachments.add("c:/test.txt")

I see the file contents printed out but the attachment statement still 
throws the same exception.

Thanks for your help though.



> On Fri, 2002-08-23 at 11:21, xWestler wrote:
> > 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!
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list