hMailServer External Copies

This is an old script, don’t plan to update/support it. I’m leaving it here for reference only!

I was recently asked by a friend to help setup a small mail server at his office. I found the hMailServer the best free option for small business. I would personally recommend anyone looking for a simple powerful (not to mention free) mailserver to try this one. I setup a global catch all account on the hosting provider (GoDaddy) and using the external account feature to download and distribute locally. So, we setup the server and all was well.

The very next day the guy called me and said although everything works fine, they are getting multiple copies of same mail. Further investigation revealed that everytime someone mailed 2 of more people in the same company, they all get multiple copies (depending on how many people were in the TO: CC: BCC:). Initially I couldn’t figure out what was causing this to happen. Later it was clear, everytime someone sends a mail to multiple people the external account (with catch all enabled) receives a copy for each mail address. When hMailServer download from this account it gets multiple mails and it forwards each one to the recipients. This is not a problem with hMailServer but it does bother everyone.

Finally I came up with a solution and so far it seems to work fine. I wrote a small script that computes a hash of every incoming mail and checks if it is an exact copy. The subject line of copies are marked allowing them to be deleted.

The script could be found here.

This is to be placed in the hMailServer\Events folder. If you have other scripts in the existing file you’ll need  to copy and paste the script manually. Now to delete copies just add a global rule that deletes all mails with -~!GLOBAL MAILBOX COPY!~- in subject line.

Hope this works for you!

24 thoughts on “hMailServer External Copies


  2. Hi

    I have copied your script and created global rule but still i got duplicate messages

    I am using hMailServer 5.4-B1931


    • From what I can see from the screenshot, the rules “Search Type” should be “Contains” and not Equals. Just make the change and you should be good to go.

      • Hi

        it worked but purpose of having catchall account did not got succeeded.
        Like earlier i sent 3 mails to , and each one use to get 3 copies each there was three recipient in a mail. Then I updated your script and then it stopped giving multiple copy but only 1 recipient in email got the email and other two recipient did not got email

        • This could be due to your routing rules… Make sure “Deliver to recipients in MIME headers” is enabled for your External Account

          • Hi
            yes “Deliver to recipients in MIME headers” is enabled also “Allow route recipient” also enabled

        • Could you send me a screenshot of the global routing rule? Also please do the below test,
          -remove the global rule to delete copies (MIME routing to be kept as it is)
          -send a single mail to 3 recipients in the domain
          -do all recipients get one original copy and 2 copies with Subject containing “GLOBAL MAILBOX COPY” or not?
          if they do, there is some problem with routing / deleting rules

  3. Hello!

    Was having an issue of diplicating messages in Hmail and started to use your script.
    Worked fine, but after couple of days I found a large delivery queue, about 150 messages. All of them had the same problem (and were not able to be delivered by the same reason) – field “To:” was empty.
    Disabled the script – all goes fine. Enabled – queue again.

    Can you help me? What it could be caused by? If you need any kind of logs from me, just ask.

  4. Hi,
    i use your script and some mail dont arrive in the local mailbox, in this condition:
    i use an excternal catchall account via pop3
    hMailServer 5.3.3-B1879
    “Deliver to recipients in MIME headers” is enabled
    “Allow route recipient” enabled or disabled it´s the same
    if the server gets 2 or more mails at the same time from the external account wich are nearly the same (from, to, subject) – some mails do not arrive in the local account – if more than one recipient is in the MIME header – some recipient get all mails and one not all
    the mails are not deletet – this rule is deactivated
    it looks like a threading problem in the hmail-server at delivery – but no error is logged

  5. Hi:
    Found your script (thank you!) and wanted to try. Do you have any idea why I get an error message (German) saying there is a “compiler problem in Microsoft VBScript – Error: 800A0400 – Description: instruction expected – Line: 58 Column: 3 – Code: Option Explicit”

  6. I have solved above problem (Option Explicit has to be frist line in script) but when using the script ALL messages will be deleted and not only the additional duplicates as meant. So non of the duplicates goes thru.

  7. Also found out the second problem. If you are sending the same Email several times (for testing) the script identifies it also as copy. Maybe the hashlist should be delete every time after the script ran?!? But that’s only an idea. I’m not good at all in scripting.

  8. Me again … ;-)

    Can you confirm that the script does NOT work if an email only differs because of the attachment? I think to have recognized that only the email intent is compared to find out duplicates but not including the attachment.

  9. Hi Chirs,
    The script does take into account the names of the attached files but not the content of the files.

    Hope this helps


  10. Hi Hermant,
    Thank you. But what I do not understand is that I get a report for example which is sent to 3 persons with the same email content BUT DIFFERENT attachments with different file names (so that should work as you mention above) BUT ALL 3 (?!?) will be marked as copy and therefore would be deleted. This report comes in 3 times a day. Could that be a reason – same email 3 times the day?

    • Chris, the HASH (to check if the mail is a copy) is a combination of Body & From & To & Subject & Attachments & Recipients… I’m not sure why the mails still get through.

      A quick and dirty fix would be to change

      Dim aHashArray(1000)
      Dim aHashArray(10)

      and all the for count loops e.g.

      For Count = 1 to 999
      For Count = 1 to 10

      This would only keep hash for last 10 mails processed by the server. So if the new mails (with similar content) come in lets say after one hour, there is a high possibility of them going through as new mails. You could adjust the value to suit your daily / hourly average mail count. Lower values would solve your problem but would increase the risk of receiving copy mails.

  11. Hi,
    Thank you very much for this quick response. As I’m only a user of scripts but not aware of writing any by myself you clear comments help a lot.
    But what I’m asking myself is why keeping hash for more than 5, 10 or more emails anyway? Shouldn’t it check emails just for the moment of downloading from a catch-all-mailbox and then it can be deleted. A next completely NEW check should be done with the next download 5 min later for example which is or can be independent from the one done before.

  12. … sorry for asking again but am I correct that the change you suggested above would be fixed ONLY by changing “Const MaxHashFileSize = 1000″ to 10. This would change all constant you mentioned?

  13. just an idea – isn’t there a unique ID (you know, that very long hex number) in each email which you could use to detect identical copies of an email instead? wouldn’t that be simpler?
    i’m currently switching from mercury to hmail, so i’m having to deal with issues like this as well :)

  14. Dear All,

    I have a big problem can anybody please solve it.
    Problem- we have a Google Catchall account we have configured this email account to Recieve & distrubute the email from local to outside & outside to local users but whenever a local user like emails to receices email from as ABC@MYDOMAIN.COM why is this happening i mean outside domain users recieves email from THE CATCHALL Account i do not wanted that because whenever outside user reply to it goes to PLEASE HELP ME.

  15. hi hemant,
    thanks for your script, while using your script i got below error

    “ERROR” 5352 “2014-08-08 11:11:58.026″ “Script Error: Source: Microsoft VBScript runtime error – Error: 800A01A8 – Description: Object required: ‘oMessage’ – Line: 50 Column: 3 – Code: (null)”

    pl. help