Friday, July 31, 2009

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.

8 comments:

orangepips August 2, 2009 at 4:01 AM  

Thanks for pointing out hMailerServer. Have you ever tried the Apache James project? It's also a mail server. Would be curious to know if you'd tried it how you thought it compared.

cfSearching August 2, 2009 at 8:33 PM  

@orangpips,

No, I have not really used it. Though I did just install it and it seemed easy enough to configure. http://wiki.apache.org/james/JamesQuickstart

-Leigh

Matt Brown August 12, 2009 at 1:58 PM  

Do you know of anyone using hmailserver in production? I was thinking about using it in a small to medium size business user wise.

cfSearching August 12, 2009 at 3:17 PM  

@Matt,

Sorry, no. But you might ask some questions over at the hmailserver forums (if you have not already). Just too see if it would be a good fit for your production environment.

-Leigh

SREENIVAS August 14, 2009 at 12:03 AM  

Hi,

Thank you,
I would like to say its very useful.

I am looking same topic since 1 month. Actually I had install hmailserver but configuration done some mistake.

my requirement like

1. I am planning create one webserver i.e in mymachine and also i want configure the other machine i.e clients.
2. I want test intranet mail services and also check to outside mail servers like I want sent my mail to other mail services(gmail,hotmail or any company mails id..) is it possible?
3. I want configure minimum 5 machine? is it possible?

Advance Thanks

Sreenivas

cfSearching August 14, 2009 at 12:21 PM  

@Sreenivas,

Yes, you could send email to servers outside any "local" domains you establish by enabling the "Local to external email addresses" option.

Of course that would be "live" email, so use caution.

-Leigh

Raymond Camden August 28, 2010 at 8:12 AM  

I'm using hMailServer w/ CF and love it. Thanks for this article. One question. I can email to foo@foo.com, if I have a domain set up for foo. I can create a catch all that forevers stuff to foo, so that allows *@foo.com to work too. However, is there anyway to do *@*.com? I'd like ALL email sent to hMailServer to be available via my local mail client while testing.

cfSearching August 29, 2010 at 10:05 AM  

Yes, I was wondering that myself. But never did figure out if it was possible. The closest I came was using domain aliases. Not quite the same as allowing *@*.com. But a little better than creating 20+ sets of addresses for 20+ domains individually.

http://www.hmailserver.com/documentation/latest/?page=reference_domains

-Leigh

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Header image adapted from atomicjeep