Installing a Development Mail Server for Testing CFMAIL
Occasionally I need to run some cfmail tests in an environment that does not have access to a mail server, or only a live server I do not want to use for testing. A while back I stumbled across the hMailServer program which is a great tool to have in those situations. Although it can function as a full fledged mail server, it can also be configured to act as a local mail server only. I have not used it in a while, but I found myself needing to install it this week. It is pretty easy to configure. But my memory was a little hazy on a few points. So I thought I would write up some instructions as a reference for next time.
The basic process is very simple. You just install the mail server and create a fake domain with a few email addresses. Then modify the mail server settings to ensure it does not allow messages to be sent to external email addresses (ie the outside world).
The latest stable version (currently 5.2) can be installed in just a few steps. You only need to create an Administrator password when prompted. Then once the installation is complete, log into the Administrator using the password you selected during the installation.
Before you can create email addresses you obviously need a domain. So from the left menu select Domains > Add and enter the desired name on the General tab. I chose the wildly imaginative domain name: psuedo-yahoo.com. Then click Save to actually create the domain.
Now to add an email address, just select your new domain in the left menu and expand it. Then click Accounts > Add. On the General tab enter an address and password and click Save to create the new email address. There are other settings you can configure, but for now address and password are the minimum information needed. (Okay, technically password is not required but it is good sense to assign one anyway). Then repeat the steps to create additional addresses as needed.
Once you have created a few email address, check the Settings > Protocols section and make sure both SMTP and POP3 are enabled. So you can both send and receive emails using the more common protocols.
Since I only wanted to send emails locally, not to the outside world, I selected Advanced > IP Ranges then modified the settings for My Computer so the mail server would only allow deliveries from local to local email addresses. Then I modified the settings for the Internet zone and unchecked all of the delivery options. So nothing was allowed for this zone. (Note, you configure the settings differently but do not check "External-to-External" unless you know what you are doing, as it can create an open relay that might be used for spam).
Now before you start sending emails from ColdFusion, it is a good idea to verify hMailServer is configured properly, using a local email client. I chose Outlook Express because I never use it for email. Under the account settings I entered 127.0.0.1 for both the SMTP and POP servers. So the all emails would only go through the local hMailServer. For user account information, I entered one of the test email addresses I created.
Next, I tried sending a message to an external email address. I used my real email address to be safe. (Just in case I messed up the configuration). As I hoped, my attempt to send a message to an external address was rejected. One test down, one to go.
Finally, I sent a local message to one of the other email addresses for my fake domain. This time the message went through successfully. So I was now ready to start sending mail from ColdFusion. I logged into the ColdFusion Administrator and under mail settings I entered the local IP (127.0.0.1) and one of my fake email addresses:
Once the settings were confirmed, I sent a test message with <cfmail>. Then retrieved it a few seconds later with <cfpop> .. and voila. Instant development mail server.
<!---
Send message
--->
<cfmail to="memyselfandI@psuedo-yahoo.com"
from="cfsearching@psuedo-yahoo.com"
subject="Just Because"
type="html">
<h1>This is a Test</h1>
It is only a test. Had this been a real email,
there would be meaningful content here.
</cfmail>
<!---
Retrieve message
--->
<cfpop action="getAll"
server="127.0.0.1"
username="memyselfandi@psuedo-yahoo.com"
password="#thePassword#"
name="getMail"
/>
<cfdump var="#getMail#"
label="Messages for memyselfandI@psuedo-yahoo.com" />
Obviously there is much more to mail server configuration, but that should be enough to get you started. So if you ever need a development only mail server on windows, consider giving hMailServer a try.