Add Rules using VBS

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
ewieldra
Normal user
Normal user
Posts: 37
Joined: 2008-04-24 23:23
Location: The Netherlands

Add Rules using VBS

Post by ewieldra » 2012-09-10 22:29

Hi All,

I'm trying to create an VBS script for adding rules, i'm able to create the basic rule.
But i cannot figure out how to add the criteria and actions. I hope someone can help me

Dim obAddRules
Set obAddRules = obApp.Rules.Add
obAddRules.Name = "test"
obAddRules.UseAND = True
obAddRules.Active = True
obAddRules.Save
obAddRules.MoveUp

Criteria
Field : TO
Comparison : Contains
Value : @domain.com

Field : X-hMailServer-Spam
Comparison : Equals
Value : YES

Field : Recipient list
Comparison : Not Contains
Value : spam@domain.com

Actions :
Forward e-mail
To : spam@domain.com
Delete e-mail

Thnx

Best regards,

Emiel
Best regards,

Emiel Wieldraaijer
The Netherlands

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

Re: Add Rules using VBS

Post by mattg » 2012-09-11 01:53

A quick look at the COM API documentation shows that the criteria and actions are on RULE not on RULES

After you create the rule, then you would need to reference the rule by name, and then add the criteria and actions

I'd guess something like
objRules.item(0).actions.add()
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

ewieldra
Normal user
Normal user
Posts: 37
Joined: 2008-04-24 23:23
Location: The Netherlands

Re: Add Rules using VBS

Post by ewieldra » 2012-09-11 15:06

Hi,

Thnx for the reply but it's not helping me, i've already looked in the PhPWebAdmin as an example

Best regards,

Emiel
Best regards,

Emiel Wieldraaijer
The Netherlands

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Add Rules using VBS

Post by ^DooM^ » 2012-09-11 18:57

ewieldra wrote:Hi,

Thnx for the reply but it's not helping me, i've already looked in the PhPWebAdmin as an example

Best regards,

Emiel
Then you need to find someone that knows this stuff and pay them to do what you need.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

ewieldra
Normal user
Normal user
Posts: 37
Joined: 2008-04-24 23:23
Location: The Netherlands

Re: Add Rules using VBS

Post by ewieldra » 2012-09-11 19:03

@^Doom^

I thought this is called a Community Forum, otherwise i would use the support button and filled in the contact form..
I'm asking for an anwser not something i can read in the help..
Best regards,

Emiel Wieldraaijer
The Netherlands

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Add Rules using VBS

Post by ^DooM^ » 2012-09-11 19:06

You were given an answer also look at the PHPWebAdmin, it shows you there quite clearly how to add rules.

If you can't make it work from the example, then you need to find someone that can. We are not here to do your work for you and we are not paid to support this free open source mailserver either. We do this off our own backs so don't start getting all high and mighty with me or you will find yourself without any help at all.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

ewieldra
Normal user
Normal user
Posts: 37
Joined: 2008-04-24 23:23
Location: The Netherlands

Re: Add Rules using VBS

Post by ewieldra » 2012-09-11 19:56

^Doom^

I don't know What's your problem ..... "so don't start getting all high and mighty with me or you will find yourself without any help at all" .. you need help..

This is the reason why don't ask anything anymore on forums yeah ban me .. no problem ..

Have a nice day..
Best regards,

Emiel Wieldraaijer
The Netherlands

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Add Rules using VBS

Post by ^DooM^ » 2012-09-11 21:18

ewieldra wrote:.. you need help..
No clearly it is you that required the help and it was given to you yet for some reason you want everyone else to do your work for you. Matt was kind enough to point you in the right direction yet for some reason you dismissed his help as not being relevant. Now either you are going to throw your toys out the pram or you can get on with it. Your choice.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

ewieldra
Normal user
Normal user
Posts: 37
Joined: 2008-04-24 23:23
Location: The Netherlands

Re: Add Rules using VBS

Post by ewieldra » 2012-09-12 00:18

Sorry i don't need help, just someone pointing me in the good direction

The documentation is not complete for the HM5 version and is hard to read, this information is taken from the HM4 documentation. The HM4 documentations has some more examples. Maybe you can add this example to the latest documentation (or not)

Code: Select all

Dim obApp
Set obApp = CreateObject("hMailServer.Application")
Call obApp.Authenticate("Administrator", "yourhmailserverpassword")

Dim newRule
Set newRule = obApp.Rules.Add
newRule.Name = "Move Spam to Spam Account"
newRule.UseAND = True
newRule.Active = True
newRule.Save
newRule.MoveUp

'Add a criteria
Dim newCriteria 
Set newCriteria = newRule.Criterias.Add

newCriteria.RuleID = newRule.ID
newCriteria.UsePredefined = true
newCriteria.PredefinedField = 7        'recipientList
newCriteria.MatchType = 6 'not Contains
newCriteria.MatchValue = "spam@domain.com"
newCriteria.Save

Dim newCriteria2
Set newCriteria2 = newRule.Criterias.Add
            
newCriteria2.RuleID = newRule.ID
newCriteria2.UsePredefined = true
newCriteria2.PredefinedField = 2        'To
newCriteria2.MatchType = 2 'Contains
newCriteria2.MatchValue = "@domain.com"
newCriteria2.Save          

Dim newCriteria3
Set newCriteria3 = newRule.Criterias.Add
            
newCriteria3.RuleID = newRule.ID
newCriteria3.UsePredefined = false
newCriteria3.HeaderField = "X-hMailServer-Spam"
newCriteria3.MatchType = 1 'Equals
newCriteria3.MatchValue = "YES"
newCriteria3.Save          

'Add Action

Dim newAction
Set newAction = newRule.Actions.Add

newAction.TO = "spam@test.com"
newAction.Type = 2
newAction.RuleID = newRule.ID
newAction.Save

Dim newAction2
Set newAction2 = newRule.Actions.Add

newAction2.Type = 1
newAction2.RuleID = newRule.ID
newAction2.Save

newRule.Save
Best regards,

Emiel Wieldraaijer
The Netherlands

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

Re: Add Rules using VBS

Post by mattg » 2012-09-12 04:01

The COM API changed considerably between ver 4 and ver 5.

That example you show, may just work however.

I see that it uses 'rule' not 'rules', which is exactly what I was telling you above.
Also, I didn't point to the PHPWebadmin, I pointed to the documentation and tried to show you why you weren't getting the result you wanted.

I'm with Doom. Not our job to do the work for you.
ewieldra wrote:The documentation is not complete for the HM5 version and is hard to read,
The documentation for ver 5 is different for sure, but incomplete?
I agree that the COM API documentation especially is hard to read, that's why I didn't just point to it and say RTFM, I actually tried to tell you what you were doing wrong.

It seems some communication barrier stopped you seeing what I wrote, and you wrote if off as irrelevant without understanding what I was trying to say.

Again that example you found may just work with the Ver 5 COM API, but then again it may not either.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

ewieldra
Normal user
Normal user
Posts: 37
Joined: 2008-04-24 23:23
Location: The Netherlands

Re: Add Rules using VBS

Post by ewieldra » 2012-09-12 20:40

@Mattg

It could be me but i said thanks for you reply and that your example did not help me much.. nothing more nothing less.
you pointed me indirectly to the documentation basicly just like saying RTFM further I did not say .. "YOU MUST HELP ME" so ^Doom^ conclusion is based on ehhhh nothing... i just made a reply so others who are willing to help could help me

So if you are with ^Doom^ i hope you two will live happily ever after

The HM5 Documentation is incomplete for example
RuleActionType are missing in version 5 Or i cannot find them but are available in version 4

1, delete the email
2, forward the email to another address
3, reply to the sender of the email
4, move the message to an IMAP folder
0, undefined behaviour (don't use)


Best regards,

Emiel
Best regards,

Emiel Wieldraaijer
The Netherlands

KamalaRider
New user
New user
Posts: 2
Joined: 2014-11-06 05:35

Re: Add Rules using VBS

Post by KamalaRider » 2016-06-15 09:24

^DooM^ wrote:You were given an answer also look at the PHPWebAdmin, it shows you there quite clearly how to add rules.

If you can't make it work from the example, then you need to find someone that can. We are not here to do your work for you and we are not paid to support this free open source mailserver either. We do this off our own backs so don't start getting all high and mighty with me or you will find yourself without any help at all.
Although 4 years after, I just had to comment to this EXTREMELY stupid answer, I'm a VERY experienced software developer and I can't figure it out either.

I'm either not looking for someone to do the job, just point me in the right direction.
You might think that we can read your thoughts and what you know about it, WE CAN'T unless we have working documentation, sorry, not a mind reader.

That answer to ewieldra was rather ignorant, childish and arrogant.
I'm not at all surprised hMailserver hasn't become more popular if the attitude of the people behind it can't answer questions in a mature and humble fashion.
It's not the first time I have reacted towards these arrogant answers, but it's the first time I respond.
Luckily I can find my way through developer issues, built my own mail gateway rejector because the documentation on hMailServer is below the level of decent, even if I do think it's a VERY good mail server.

A word of advice if the people answering the questions are the same as it was when this post was posted, if you want hMailserver to live, either complete the documentation with real examples or answer the questions with humility and in a positive spirit. hMailServer COULD be a commercial product but it won't until some work has been done and support/advice/comments will improve.

User avatar
jimimaseye
Moderator
Moderator
Posts: 8131
Joined: 2011-09-08 17:48

Re: Add Rules using VBS

Post by jimimaseye » 2016-06-15 09:46

Wow. Now THERE is a lesson.

a, break forum rules but interfering with other peoples dead threads
b, Troll. Offer nothing productive or important and just make negative comments and provocations to others about others.
c, criticise the very people that help
d, deride Hmailserver - despite its success and being the very product he chooses to use.

Ill make a note of it i the documentation:

Heading: HOW TO BURN YOUR BRIDGES
Detail: viewtopic.php?p=187245#p187245
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

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

Re: Add Rules using VBS

Post by mattg » 2016-06-15 11:03

I don't know what I did wrong 4 years ago, even now when I re-read that thread.
I gave the answer to the OP's question.

@KamalaRider do you actually have a question or are you just trolling for fun...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

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

Re: Add Rules using VBS

Post by SorenR » 2016-06-15 17:33

mattg wrote:I don't know what I did wrong 4 years ago, even now when I re-read that thread.
I gave the answer to the OP's question.

@KamalaRider do you actually have a question or are you just trolling for fun...
I know what's wrong :!:

And this is where it begins...
Image

Get it ?? :mrgreen:
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Add Rules using VBS

Post by ^DooM^ » 2016-07-23 16:00

In all fairness i couldhave handled that a bit better, i must of been having a bad day when i wrote that, so apologies if i offended anyone 4 years ago, i'll try not to lose to much sleep over it!
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: Add Rules using VBS

Post by percepts » 2016-07-23 18:45

Blimey, I thought you were long gone. You have my sympathy, I know how it is when its clear the questioner knows exactly what they want and could probably do it themselves but aren't prepared to do the donky work themselves.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Add Rules using VBS

Post by ^DooM^ » 2016-07-24 11:25

Still alive and kicking, mostly ;)
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

DjGL
New user
New user
Posts: 26
Joined: 2006-12-15 14:55

Re: Add Rules using VBS

Post by DjGL » 2016-09-08 13:49

For all searching for the PredefinedIds, you can find it in the webadmin code in include/rule_strings.php.
Even though it is PHP code I think those wanting to use it can read it:

define("eFTUnknown", 0);
define("eFTFrom", 1);
define("eFTTo", 2);
define("eFTCC", 3);
define("eFTSubject", 4);
define("eFTBody", 5);
define("eFTMessageSize", 6);
define("eFTRecipientList", 7);
define("eFTDeliveryAttempts", 8);

define("eMTUnknown", 0);
define("eMTEquals", 1);
define("eMTContains", 2);
define("eMTLessThan", 3);
define("eMTGreaterThan", 4);
define("eMTRegExMatch", 5);
define("eMTNotContains", 6);
define("eMTNotEquals", 7);
define("eMTWildcard", 8);

define("eRAUnknown", 0);
define("eRADeleteEmail", 1);
define("eRAForwardEmail", 2);
define("eRAReply", 3);
define("eRAMoveToImapFolder", 4);
define("eRARunScriptFunction", 5);
define("eRAStopRuleProcessing", 6);
define("eRASetHeaderValue", 7);
define("eRASendUsingRoute", 8);
define("eRACreateCopy", 9);
define("eRABindToAddress", 10);

Post Reply