Change subject with script

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
screenman47
New user
New user
Posts: 20
Joined: 2017-04-27 17:11

Change subject with script

Post by screenman47 » 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.

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

Re: Change subject with script

Post by SorenR » 2020-04-02 19:27

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?
SørenR.

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

screenman47
New user
New user
Posts: 20
Joined: 2017-04-27 17:11

Re: Change subject with script

Post by screenman47 » 2020-04-02 20:04

Within a rule - Action - Run Function - SpamToSubject

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

Re: Change subject with script

Post by SorenR » 2020-04-02 20:27

screenman47 wrote:
2020-04-02 20:04
Within a rule - Action - Run Function - SpamToSubject
What does line 31 in your EventHandlers.vbs look like?
SørenR.

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

screenman47
New user
New user
Posts: 20
Joined: 2017-04-27 17:11

Re: Change subject with script

Post by screenman47 » 2020-04-02 20:44

The first line of the script.
Sub..........

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

Re: Change subject with script

Post by SorenR » 2020-04-02 21:00

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?
SørenR.

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

screenman47
New user
New user
Posts: 20
Joined: 2017-04-27 17:11

Re: Change subject with script

Post by screenman47 » 2020-04-02 21:08

No. I just edited the sample provided by adding the 4 lines.

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

Re: Change subject with script

Post by SorenR » 2020-04-02 22:32

Well, something is weird in your EventHandlers.vbs

Care to PM it to me for review?
SørenR.

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

screenman47
New user
New user
Posts: 20
Joined: 2017-04-27 17:11

Re: Change subject with script

Post by screenman47 » 2020-04-03 12:49

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.

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

Re: Change subject with script

Post by SorenR » 2020-04-03 13:03

hMailServer makes a "compiled" binary version of the script in memory for speed during startup and when you press the button 😏
SørenR.

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

Post Reply