Norfeldt
Norfeldt

Reputation: 9688

Python: Open outlook compose instance with attachments

I know that this exist: compose email in outlook with attachment - but it's not python.

I want to use python to open an Outlook compose instance with some files attached and recipients in To and CC fields (an perhaps had some text in the message). The user should then be able to write in the message and press send.

I was thinking that win32com might do it, but haven't found some examples.

How can this be done ?

Upvotes: 1

Views: 2950

Answers (2)

Norfeldt
Norfeldt

Reputation: 9688

inspired by @Timo I found the following solution to work for me.

import subprocess
outlookpath2doc = '"C:/Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"'
compose = '/c ipm.note'
recipients = '/m "[email protected]; [email protected]&subject=Please take a look at this"'
attachment = '/a "' + path2doc + '"'
command = ' '.join([outlookpath2doc, compose, recipients, attachment])
process = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE)

Upvotes: 4

Timo
Timo

Reputation: 263

You could use command line arguments to start Outlook:

outlook /a "C:\path\to\attachment" /c ipm.note /m "[email protected]; [email protected]"

In python, just use os.system(command) to open outlook with your switches.

You can see all available switches on the Microsoft website.

Upvotes: 2

Related Questions