I have to prepare e-mail in python (e-mail address, body html, attachments 
etc.) and show Outlook window for user who will check everything and correct if 
necessary and will be able to send it.
My script work well :


o = win32com.client.Dispatch("Outlook.Application")
Msg = o.CreateItem(0)
Msg.To = "a...@gmail.com"
Msg.CC = ""
Msg.Subject = "The random subject"
Msg.HtmlBody = "<h1>content of e-mail</h1>"
Msg.Attachments.Add(attachment1)
Msg.Display()

This script work well but I have some problem with my Outlook 2019 or Command 
window (Win 10, 64). When Outlook is closed i can call my script using Shell() 
or ShellExecute() and everything is ok but when MS Outlook is open my script 
doesnt work. I use the same  Shell() or ShellExecute() function and still does 
not work although windows executing this script. It stops in the loine 
"win32com.client.Dispatch("Outlook.Application")". I tried many tricks and I 
gave up. The most important is that when I use windows command line and run my 
script manyally (python sendoutlookmail.py) everything works well regardless of 
state of Outlook (open or closed).
I think there is a different between calling script via Shell() function and 
run it directly from command line.
I tried of course solution as follows:

Set obj = CreateObject("WScript.Shell")
obj.Run sPythonFile 

but its the same situation. I createt bat file and I execute this bat file 
which has inside commant to execute my python script.

I have no idea how to run python script on my system that works the same as I 
call it directly from windows command line.

regards
Wojtek
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to