Installation and configuration of local Mail server for Windows (hMail Server)

This is not exactly Magento related post, but it might be useful when you are setting up a dev environment on your local machine. There are many good and free mail servers out there which are relatively easy to install on your Windows machine, but the problems may occur when you try to configure all the bits and pieces of your system so you can actually use your local mail server for something other than producing system errors 🙂 .

When I started working with PHP a long time ago, I was (naturally) looking for a mail server that could be used on my local machine. For some reason that is now long forgotten, I have decided to use hMail Server (freeware). Since it never failed me, it stayed in my standard set of must-have tools. In this post I’ll try to present a step-by-step manual on how to install and configure your system to use hMail Server.

Although this post might be a bit lengthy, please, don’t be scared :). These are all simple steps and if you have any experience as a Windows user, you should be able to skip reading the most of them.

System properties (listed just as a reference)

  • Windows 7 Professional with the latest updates
  • MySQL 5.0.51b
  • Apache 2.2.17

Part 1 – Installation and Database configuration

  • Download hMail Server from their download page. My suggestion is to get the latest production release as it is the most stable one;
  •  Start the installer and pick “Full installation”. That should include Administrative tools which are very useful;
  • When asked, set MySQL as your mail database. You don’t need to create the database manually, installer will do that for you;
  • When you complete the installation wizard, database configuration wizard will appear where you should pick “Create new mail database” option;
  • Copy libmysql.dll to /hMailServer/bin directory;
  • Enter the MySQL server and user info.  You can use localhost as server name and whatever port you used for MySQL (default is 3306);
  • Pick the database service from the dropdown so that hMail server can hook to it. It’s usually listed as “MySQL” but  can be listed as “WAMP Mysql” (or whatever name you used) if you have WAMP installed;
  • Database configuration should be completed now and you can proceed to run the hMail Server Administration tool.

Part 2 – Configuring Windows DNS, port and firewall settings

  • The first thing you need to do is add a couple of entries to the Windows’ hosts file. Click on the Windows Start button and search for Notepad. Right click Notepad.exe and choose “Run as Administrator”. This will ensure that you will be able to save the “hosts” file once you’ve finished adding the changes, since the file is protected by the operating system by default;
  • Open the hosts file in Notepad. It’s located in WindowsSystem32driversetc folder;
  • add the following at the end of the file (you can put anything instead of “localserver”):
127.0.0.1 mail.localserver.com
127.0.0.1 localserver.com
127.0.0.1 smtp.mail.localserver.com
127.0.0.1 pop3.mail.localserver.com
  • Open “Windows Firewall” form Control Panel or by searching for it in the Start menu;
  • Go to “Inbound rules” in the left bar and create a new rule for a Port. Type the port numbers for SMTP, POP3 and optionally IMAP protocols in TCP > Selected local ports field. You don’t need to create 3 rules for each port, because you can add all three of them with a comma separator (for example: 25, 110, 143);
  • Enter the name of the rule. Something like “hMail open ports” should do;
  • If you have any custom firewall installed, either stand-alone or as part of your AV software, you might want to look at your software’s documentation and see how to open ports. The ports you need to open are 25, 110 and optionally 143 if you plan to use IMAP.

Part 3 – Configuring hMail server

  • Create a new Domain in the hMail Administrator and put “mail.localserver.com” in the Domain field;
  • Create one administrator mail account by going to “Domains > mail.localserver.com > Accounts > Add” and choosing “Server” in the “Administration level” field. We will use “master@mail.localserver.com” as an example;
  • Go to the “Delivery of e-mail” tab in the “Settings > Protocols > SMTP” and enter  “mail.localserver.com” in the “Local Host Name” field;
  • Go to “Settings > Advanced > TCP/IP Ports” and configure each of the sub-entries to use 127.0.0.1 as IP address.

That’s it! Your local mail server is now up and running. The only thing you need to do now is to connect your newly created local mail address to some e-mail application. I will post here a quick how-to tips for Thunderbird.

Configuring Thunderbird mail account

  • Go to “Tools > Account settings” in the Thunderbird main menu and create a new account (“Account actions” button, then “Add new account” option);
  • Use “master@mail.localserver.com” e-mail address (the one you have created in the hMail Administration) and set “Outgoing server” to “smtp.mail.localserver.com”;
  • Go to “Server settings” in your newly created mail account branch and use “pop3.mail.localserver.com” as “Server name”. “User name” field on this page should be the full name of your e-mail address, so, it would be “master@mail.localserver.com”

You are now ready to use your local e-mail address for your local Magento installation. If you run into any trouble, you can always use the Diagnostics tool from the Utilities menu  or check for error messages in the Status window of the hMail Administrator. I will also suggest you to explore the Administrator application and set up one of the many useful logging and debugging parameters as well as playing with the options for mail accounts. Of course, you should not forget to take a look at the security options too.

Have fun!