Problem automating outlook with python

Noah noah at
Sat Aug 24 06:15:05 CEST 2002

xWestler <NoThanks@^*^#*&> wrote in message news:<MPG.17d038f36d7b3105989680 at>...
> 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")
> 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)

The problem is that you are using a lowercase "add". You want "Add".
The attachment line should read:
I don't know what the "add" method is, but apparently it is something -- 
just not the same thing as "Add" :-) I could not find "add" documented.
Probably it is inherited from somewhere.

Also, you want the raw style string r"...", otherwise the \ in c:\
will get treated as an escape character and might confuse things.
It's always good to use raw strings when working with Windows style path names.


More information about the Python-list mailing list