Using hmailserver 5.6 in test environment and redirect all external mails to one address

I had to set up a test environment where i needed a test smtp mail server to test mail functionality of a pice of software.

So i installed hmailserver version 5.6 and i was trying to find a way how all mail that might be sent through this email server and has an external address domain can be redirected to an internal test mailbox.

You can do this by implementing a rule in hmailserver and a vbscript routine. This rule removes all initial to-addresses from the email header and replace them with a default to-address.

  1. I set up a mail domain in hmailserver called
  2. I created a new mailbox to receive all the redirected mails ( You can also do it with a catchall address for the domain and redirecting the mails to a non existent mail address in your domain. Then the catchall address will get all the redirected mails.
  3. I created a rule in hmailserver with criteria „Field ‚To‘ not contains ‚'“.
  4. The action for this rule is of type „Run function“ and the script function i called „OnAllOutgoingExceptLocal“. This is the name you have to give your script method later. So you can choose one of your own.
  5. I changed the scriptfile in my hmailserver script directory:
    C:\Program Files\hMailServer\Events\EventHandlers.vbs.
    I had to do it with admin rights.
    I added the following method at the end:

     Sub OnAllOutgoingExceptLocal(oMessage)
        oMessage.Subject = "Originally sent to: " & oMessage.To & ": " & oMessage.Subject
        oMessage.AddRecipient "", ""
        Result.value = 0
     End Sub
  6. I saved the vbs file
  7. In hmailserver admin tool i enabled „Scripts“ in Settings-Advanced Section an did „Reload scripts“

After that all mails sent through my smtp server are redirected to instead of being tried to be routed to external relay server.

Maybe someone else also need this help.

Schreibe einen Kommentar