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.
- I set up a mail domain in hmailserver called test.com
- I created a new mailbox to receive all the redirected mails (email@example.com). 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.
- I created a rule in hmailserver with criteria „Field ‚To‘ not contains ‚@test.com'“.
- 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.
- I changed the scriptfile in my hmailserver script directory:
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.ClearRecipients() oMessage.AddRecipient "", "firstname.lastname@example.org" oMessage.save Result.value = 0 End Sub
- I saved the vbs file
- 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 email@example.com instead of being tried to be routed to external relay server.
Maybe someone else also need this help.