Python script not running

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
DimanG
New user
New user
Posts: 15
Joined: 2016-04-26 10:11

Python script not running

Post by DimanG » 2020-07-23 14:29

Hi everybody!

I've got a sub executing Python script over the saved message file. No result. What's wrong? Or where to look for?
There are some excessive code cause I was trying to find solution.

The message file is copied successfully, but the Python script does nothing, while running manually is ok.

Thanks in advance.

Code: Select all

Sub save_body_zc(oMessage)

   oTxtBody=oMessage.HTMLbody
   Dim StrDir, strFileName, FullName, oShell, TempDir
   
   StrDir="\\srv\EXPORT\zc\"
   TempDir="\\srv\EXPORT\zc\Temp\"
   
   strFileName = trim(oMessage.subject)
   
   FullName=StrDir & strFileName & ".eml"
   TempName=TempDir & strFileName & ".eml"
   
   With CreateObject("Scripting.FileSystemObject")
      .CopyFile oMessage.FileName, TempName, True
   End With
   
   StrDir="\\\\srv\\EXPORT\\zc\\"
   TempDir="\\\\srv\\EXPORT\\zc\\Temp\\"
   
   FullName=StrDir & strFileName & ".eml"
   TempName=TempDir & strFileName & ".eml"
   
   Set oShell = WScript.CreateObject ("WScript.Shell")
	oShell.Exec("d:\Python34\python.exe d:\Python34\Scripts\zcmail.py " & Chr(34) & TempName & Chr(34) & " " & Chr(34) & FullName & Chr(34))
   Set oShell = Nothing
   
End Sub

User avatar
mattg
Moderator
Moderator
Posts: 20899
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Python script not running

Post by mattg » 2020-07-23 15:00

Probably the user that the hMailserver WINDOWS SERVICE runs under doesn't have the permissions required to run your python

Perhaps change the user that the Windows Service runs under
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

DimanG
New user
New user
Posts: 15
Joined: 2016-04-26 10:11

Re: Python script not running

Post by DimanG » 2020-07-28 16:29

Added maximal rights (local admin) to the user. Nothing changed. How can I debug the script execution? Logs contain nothing to analyze.
Manually it runs ok.

User avatar
mattg
Moderator
Moderator
Posts: 20899
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Python script not running

Post by mattg » 2020-07-28 16:51

Press Windows start orb >> type 'services.msc'

Open Services, scroll down to hMailserver
Select hMailserver, then right click, and choose properties

Select the 'log on' tab, and screen shot that, and post screenshot here

Also show a screen shot of the properties >> Security, for the folder that has your Python installation
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

DimanG
New user
New user
Posts: 15
Joined: 2016-04-26 10:11

Re: Python script not running

Post by DimanG » 2020-07-29 17:45

Screenshots are in Russian. I can tell in some words: the domain user the service hMailServer runs under is a local admin. Full rights are given for it on the folder and all subfolders and files where Python is located. The script is executed manually under this user with success. But what's inside hMailServer - I can't find out. Only message file is copied to another location - I did so when the script stopped working (it worked some days, and nothing was changed in the system).

User avatar
mattg
Moderator
Moderator
Posts: 20899
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Python script not running

Post by mattg » 2020-07-30 02:34

Try adding some event logging to your hmailserver script

like
EventLog.Write(TempName)

just before the python script is called to make sure that the variables are set correctly
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

DimanG
New user
New user
Posts: 15
Joined: 2016-04-26 10:11

Re: Python script not running

Post by DimanG » 2020-08-03 22:22

Tried several logging events in vbs, py and cmd scripts and found out that everything is ok with variables, but the cmd-script doesn't run at all. The hMailserver log is always full of Script Error records with some unknown codes. Is there any way to see what's wrong with of WScript.Shell Exec command?

Thank you for help

DimanG
New user
New user
Posts: 15
Joined: 2016-04-26 10:11

Re: Python script not running

Post by DimanG » 2020-08-04 00:09

Last example:
"ERROR" 7560 "2020-08-04 00:47:02.259" "Script Error: Source:

User avatar
SorenR
Senior user
Senior user
Posts: 3624
Joined: 2006-08-21 15:38
Location: Denmark

Re: Python script not running

Post by SorenR » 2020-08-04 10:52

I don't use Python but how about this?

Code: Select all

Sub save_body_zc(oMessage)

    Dim StrDir, strFileName, FullName, WshShell, oExec, TempDir

    StrDir="\\srv\EXPORT\zc\"
    TempDir="\\srv\EXPORT\zc\Temp\"

    strFileName = trim(oMessage.subject)

    FullName=StrDir & strFileName & ".eml"
    TempName=TempDir & strFileName & ".eml"

    With CreateObject("Scripting.FileSystemObject")
        .CopyFile oMessage.FileName, TempName, True
    End With

    FullName=Replace(FullName, "\", "\\")
    TempName=Replace(TempName, "\", "\\")

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("d:\Python34\python.exe d:\Python34\Scripts\zcmail.py " & Chr(34) & TempName & Chr(34) & " " & Chr(34) & FullName & Chr(34))

    Do While oExec.Status = 0
        WshShell.Run "powershell Start-Sleep -Milliseconds 100", 0, True
    Loop

    EventLog.Write("Return code on d:\Python34\python.exe d:\Python34\Scripts\zcmail.py " & Chr(34) & TempName & Chr(34) & " " & Chr(34) & FullName & Chr(34) & " was " & oExec.Status)
    Set oExec = Nothing
    Set WshShell = Nothing

End Sub
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

Post Reply