سؤال

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 ?

هل كانت مفيدة؟

المحلول

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 "recipient@example.com; recipient2@example.com&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)

نصائح أخرى

You could use command line arguments to start Outlook:

outlook /a "C:\path\to\attachment" /c ipm.note /m "recipient@example.com; recipient2@example.com"

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

You can see all available switches on the Microsoft website.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top