How to use COM object to create rules?

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
User avatar
matty
Senior user
Senior user
Posts: 330
Joined: 2005-08-22 16:29
Location: New York
Contact:

How to use COM object to create rules?

Post by matty » 2005-08-22 16:44

Does anyone know how to use the COM object to create a rule? I set up a forwarding rule manually but I need to do it for hundreds of accounts so I am trying to set up a VBS to do it using the COM object. The documentation on the website does not detail the Rules property of the Account object and the hmail admin has no help file either. I am using hmail 4.0 b125.

cmurphy54
Senior user
Senior user
Posts: 550
Joined: 2004-09-25 22:11
Location: Atlanta, GA
Contact:

Post by cmurphy54 » 2005-08-22 17:42

Here's how you might do it using C# and the COM object, you should be able to convert it to VBS fairly easily.

I haven't actually tested the code other than to see that it compiles, but it seems like it should more or less work.

Code: Select all

            Application hMailServer = new hMailServer.ApplicationClass();
            Rule newRule = hMailServer.Rules.Add();
            newRule.Name = "Test Rule";
            newRule.Active = true;
            newRule.Save();

            //Add a criteria
            RuleCriteria newCriteria = newRule.Criterias.Add();
            //Not sure this next line is necessary...
            newCriteria.RuleID = newRule.ID;
            newCriteria.MatchType = eRuleMatchType.eMTContains;
            newCriteria.MatchValue = "test.com";
            newCriteria.UsePredefined = true;
            newCriteria.PredefinedField = eRulePredefinedField.eFTTo;
            newCriteria.Save();
            
            //Add a delete action
            RuleAction newAction = newRule.Actions.Add();
            newAction.Type = eRuleActionType.eRADeleteEmail;
            //Not sure this next line is necessary...
            newAction.RuleID = newRule.ID;
            newAction.Save();

            newRule.Save();
If you tell me what the rule you are trying to replicate is supposed to do, I can give you the proper enum values for the actions/predefined header, etc.

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2005-08-22 17:50

Enum values for action types and so on can be found here:
http://www.hmailserver.com/documentatio ... ruleaction
http://www.hmailserver.com/documentatio ... lecriteria

I know the COM documentation sucks at the moment. Before the release of 4.2, my goal is that it should actually be usable. The COM API docs should contain all objects, properties, methods and examples how they can be used. Today there's almost no examples and the descriptions are very short.

User avatar
matty
Senior user
Senior user
Posts: 330
Joined: 2005-08-22 16:29
Location: New York
Contact:

Post by matty » 2005-08-22 22:28

I got it to work. Thanks for the documentation, I did not see those pages this morning, did you just add them?

Anyway, I actually wrote a VBS to import users and domains from Merak Mailserver to hmail. I needed to create forward rules in there and you can see this posting where I posted the actual script after I got it working. It includes the rules portion if anyone is interested.

http://www.hmailserver.com/forum/viewtopic.php?p=14663

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2005-08-22 22:31

> I did not see those pages this morning, did you just add them?

Yes. Since you asked about a specific part of the API, I thought it was just as good as documenting. Feels a bit more effient than responding to the same question over and over again. :)

User avatar
matty
Senior user
Senior user
Posts: 330
Joined: 2005-08-22 16:29
Location: New York
Contact:

Post by matty » 2005-09-30 18:27

The documentation of the Domain object does nto mention a property for Max message size. Is there a way to set this on a domain using the COM objects?

Post Reply