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 0.0.0.0 till 255.255.255.255 and allow message to and from @development.com only. Have a look at the screenshot for were to find these settings and what their value should be.
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.
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\development.com\dropfolder\" & _ path(UBound(path)) 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) copy.WriteLine(original.ReadAll) copy.Close original.Close 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,
Wesley
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.
Comments have been disabled for this content.