Applies to

hMailServer 4.0 and later.


Rules enable you to define actions to take based on the contents of an email. For example, you can use rules to delete mail based on a specific subject-line, or to forward email larger than a specific size.

Rules can be defined at two different levels: Global and Account. Global rules are applied to all messages delivered to the server, regardless of which recipient they are to be delivered to. Account rules apply only to email to a specific account.

Every rule has a set of criteria and actions. When you create a rule, you add criteria that specify which email the rule should be applied to. For example, you may add a criterion that limits the rule to email containing a specific Message-ID-header. After you have added criteria, you add actions. Actions define what hMailServer should do if a message matches the criteria. For example, the action may be to forward the email, delete it or move it to a specific folder.


Here are some examples on how to implement rules.

Different search types

hMailServer supports a number of different search types. They are: Is, Contains, Less than, Larger than and Regular Expression.
  • Is: Used to specify an exact match.
  • Contains: Used to specify a partial match. For example, you might want to apply the rule to email where the Body Contains a certain word.
  • Less than: Used for numeric matches. For example, you may want to apply the rule to email where the message size is less than 1 MB.
  • Larger than: Used for numeric matches. Opposite of Less than
  • Regular expression: Using regular expression matching, you can specify more complex matchings. For example, you may apply the rule to all messages where the subject line begins with a letter and the rest of it is numeric. For more information about regular expressions, visit


Moving to IMAP folder

It is possible, when moving messages to folder using a rule, to move messages to folders as well as to sub folders. Use this syntax: Folder.Subfolder1.Subfolder2.

Miscellaneous information

60 second delay

When an email is auto-generated by a rule, for example, after a forward, it may take up to 60 seconds before the email is delivered. The message will be delivered the next time hMailServer polls the database for emails to deliver. This delay is necessary. Without it, it would be easy to create a rule that delivers messages in an endless loop which would make hMailServer use 100% CPU until the rule is deleted.

Rules loop count

hMailServer 4.2 and later can limit the number of times a message is processed in a loop. The loop limit is found in the advanced SMTP settings. If two users set up rules that make an email to bounce back and forth between them, hMailServer will only handle the email the number of times defined by rule loop count.

Encoded header fields

Headers of email messages may be encoded using different types of encoding. If you set up a criterion that searches a header field, hMailServer will try to decode that header field if possible. If the header is in Japanese, for example, the contents of the mail will not be searchable.

Search documentation