Problem automating outlook with python

Anthony Tuininga anthony at computronix.com
Fri Aug 23 20:11:51 CEST 2002


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")

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
-- 
Anthony Tuininga
anthony at computronix.com
 
Computronix
Distinctive Software. Real People.
Suite 200, 10216 - 124 Street NW
Edmonton, AB, Canada  T5N 4A3
Phone:	(780) 454-3700
Fax:	(780) 454-3838
http://www.computronix.com





More information about the Python-list mailing list