Configure hMailServer for SharePoint

There is this great free mailserver called hMailServer which can be found here. It is very stable and works definately like a charm. There is some awesome documentation and thus a breeze to configure. I wanted to use this free mail server on my SharePoint 2010 development / demo machine but got stuck with two problems to resolve.


SharePoint can not connect to a mail server that requires authentication. hMailServer is secure by default so you have to add ip-range and define that this ip-range does not require authentication. In my case I defined a range from till and allow message to and from only. Have a look at the screenshot for were to find these settings and what their value should be.

Drop folder

This one was a bit more complicated. SharePoint requires a path to a ‘drop folder’ where it can find the incoming emails. hMailServer however does not work with drop folders. It creates a folder hierarchy for each account. The dropfolder in the screenshot below is created by me. Just note the folder hierarchy.

bad sender or receiver

Even if you do direct SharePoint to one of those folders inside the hierarchy, it results in a ‘bad sender or receiver’ error when it tries to process the email. But why? It works with the default IIS smtp server right? This error occurs because the default Microsoft SMTP server adds two headers to an email: the x-sender and the x-receiver. SharePoint uses these headers when it processes the emails.


The solution to all this is the use of VBScript. hMailServer can be extended by writing some event handlers.

If we could write a script, that copies an incoming message to a ‘drop folder’ AND add the two headers, we are done. Luckily we can!

First we create a dropfolder inside the existing hierarchy.(Have a look at the screenshot above). Be sure to set the permissions for this folder to allow the SharePoint Timer Service account to make modifications!

Then - after clicking the ‘Show scripts’ button(see screenshot above) - simply open the script file ‘EventHandlers.vbs’ and add the following script.

Sub OnDeliverMessage(oMessage)
        Dim path, filename, fso, original, copy

    path = Split(oMessage.Filename, "\", -1, 1)

    filename = "C:\Program Files (x86)\hMailServer\Data\\dropfolder\" & _

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set copy = fso.CreateTextFile(filename, True)
        copy.WriteLine("x-sender: " & oMessage.FromAddress)
        copy.WriteLine("x-receiver: " & oMessage.To)

    Set original = fso.OpenTextFile(oMessage.Filename, 1)
End Sub

This should replace the commented Sub OnDeliverMessage(oMessage). Save the script., ‘Check syntax’ to be sure and click ‘Reload scripts’ to enable this freshly added script. The script simply copies ALL incoming mail messages to the ‘dropfolder’ and prepends the two mentioned headers. Now simply point SharePoint to the dropfolder and that’s it!


With this script in place you can very well use hMailServer in combination with SharePoint!

Cheers and have fun,


tip: create a catch all address for all your SharePoint incoming mail. You do not want to manually add a new address for each list you want to mail enable.


  • Nice! I'll redirect people here if they want to know how to use hMailServer with Sharepoint. (I'm the hMailServer author)

  • It's really good topic. Especially about the way for adding IP range, it saved my life :)

    Thanks a lot.

  • Great Topic!

    I just needed to use incoming e-mails in Sharepoint Lists and this works like a charm!

    Good Job Wesley!

  • Hi Wesley,

    Nice Topic wesley.. but images are not available that making me difficult to understand.

    please re-attach the images.


  • i am having an error :
    "ERROR" 2044 "2010-10-25 18:51:07.484" "Severity: 2 (High), Code: HM5016, Source: ScriptServer::LoadScripts, Description: File: C:\Program Files (x86)\hMailServer\Events\EventHandlers.vbs[nl]Script Error: Source: Microsoft VBScript runtime error - Error: 800A01A8 - Description: Object required: 'oMessage' - Line: 14 Column: 4 - Code: (null)"
    "ERROR" 2044 "2010-10-25 18:51:08.339" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01A8 - Description: Object required: 'oMessage' - Line: 14 Column: 4 - Code: (null)"

    with : windows 2008

    any sugestion?

  • There is an error in the script. I found it by chance while looking for something else in the hMailServer logs.

    The last line should be "original.Close"


  • @Onsel Akin: Thanks! Good catch!

  • Nice post. Started to use hMailServer recently and was looking for a way to handle the incoming mails.

  • If the SharePoint list email address is put into CC (carbon copy) field while sending email, then SharePoint fails to parse email message and thus not adding anything in SharePoint email enabled list.

    To overcome this issue i tried adding this line:
    If Not IsEmpty(oMessage.CC) AND oMessage.CC "" Then
    copy.WriteLine("x-receiver: " & oMessage.CC)
    End If

    Right below these lines:

    copy.WriteLine("x-sender: " & oMessage.FromAddress)
    copy.WriteLine("x-receiver: " & oMessage.To)

    Could you consider adding this addition to the original article?

  • Scrip works like charm. Just found the CC option for the script which is also working fine. is there a way to have this also for BCC?

  • Thank You. Great Post. It worked.

  • Excellent post, worked like a charm.

  • thanks for great article,

    thou i still have issue with it keep show me this error

    "Cannot save all of the property settings for this Web Part. An invalid Outlook Web Access server address was specified."

    all i change in script to my domain name even tried security full access to everyone see any differences still same error!

    did i miss something in configuration?

  • I keep hitting this page. But the pictures are missing. Can someone fix this or provide alternative pictures? Thanks

Comments have been disabled for this content.