Page 1 of 1

Change subject with script

Posted: 2020-04-02 18:39
by screenman47
When an email message matches a rule I want to run a script that changes the subject - just add "SPAM" actually.
I saw an old thread which seemed to be what I wanted and tried it out. When I do I get an error on the first line. The O/S is Windows 2016 server.

This is the script within eventhandlers.vbs

********************************************
Sub SpamToSubject(oMessage)
oMessage.Subject = oMessage.Subject & "---SPAM"
oMessage.Save
End Sub
********************************************

This is the error I get. The script starts at line 31.

*******************************************************************************************
"ERROR" 3184 "2020-04-02 15:28:31.307" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A000D - Description: Type mismatch: 'SpamToSubject' - Line: 31 Column: 0 - Code: (null)"
*******************************************************************************************


Seems a simple one even with changing the script name it will not work.

Any ideas.

Re: Change subject with script

Posted: 2020-04-02 19:27
by SorenR
screenman47 wrote:
2020-04-02 18:39
When an email message matches a rule I want to run a script that changes the subject - just add "SPAM" actually.
I saw an old thread which seemed to be what I wanted and tried it out. When I do I get an error on the first line. The O/S is Windows 2016 server.

This is the script within eventhandlers.vbs

********************************************
Sub SpamToSubject(oMessage)
oMessage.Subject = oMessage.Subject & "---SPAM"
oMessage.Save
End Sub
********************************************

This is the error I get. The script starts at line 31.

*******************************************************************************************
"ERROR" 3184 "2020-04-02 15:28:31.307" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A000D - Description: Type mismatch: 'SpamToSubject' - Line: 31 Column: 0 - Code: (null)"
*******************************************************************************************


Seems a simple one even with changing the script name it will not work.

Any ideas.
Which trigger call this sub?

Re: Change subject with script

Posted: 2020-04-02 20:04
by screenman47
Within a rule - Action - Run Function - SpamToSubject

Re: Change subject with script

Posted: 2020-04-02 20:27
by SorenR
screenman47 wrote:
2020-04-02 20:04
Within a rule - Action - Run Function - SpamToSubject
What does line 31 in your EventHandlers.vbs look like?

Re: Change subject with script

Posted: 2020-04-02 20:44
by screenman47
The first line of the script.
Sub..........

Re: Change subject with script

Posted: 2020-04-02 21:00
by SorenR
screenman47 wrote:
2020-04-02 20:44
The first line of the script.
Sub..........
You have not used "SpamToSubject" anywhere else in the EventHandlers file?

Re: Change subject with script

Posted: 2020-04-02 21:08
by screenman47
No. I just edited the sample provided by adding the 4 lines.

Re: Change subject with script

Posted: 2020-04-02 22:32
by SorenR
Well, something is weird in your EventHandlers.vbs

Care to PM it to me for review?

Re: Change subject with script

Posted: 2020-04-03 12:49
by screenman47
Okay. I have it working.

First I emptied the eventhandlers file and just entered the script I wanted. Then I tested it and I still
got the error for line 31. Strange since there was only 4 lines now in the script. So I looked at the Hmail app
and saw a button which said "Reload" - not really noticed this before since this is the first time that I have
wanted to use a script. Anyway pressed that and tried again - this time it worked.

I have been writing database software for nearly 40 years and with that I call a routine as and when I want it
used and can amend it on the fly and it all works. With Hmail server I just assumed that it would do the same
thing but it must load the vbs script at the time of startup. Did not know that. Hence my problems.

Thank you for your help on this.

Re: Change subject with script

Posted: 2020-04-03 13:03
by SorenR
hMailServer makes a "compiled" binary version of the script in memory for speed during startup and when you press the button 😏