cygwin+exim: setting up a local SMTP server for testing email applications

This is mainly a ref­er­ence for myself in case I forget how to do it later, as it took me a good deal of time to figure out.

Situation

I want to unit test appli­ca­tions that send emails. Obvi­ously I don’t want to be open­ing a dozen of real email accounts just to test this thing out. Nat­u­rally I would want to install an SMTP/POP3/IMAP server on Win­dows, and there is one free (open source) option that is quite promis­ing – hMailServer. How­ever, it still involves 2 (quite major) incon­ve­niences for my use case:

  • I have to go through the con­fig­u­ra­tion screens to create new users. i.e. if I want to send email to [email protected] I’d have to create the user account alice manually
  • I have to use an email client (like Out­look Express) to con­nect to the local POP3 server to view the emails. This seems redun­dant to me, since the files are already stored in my disks, why can’t I just view them?

The Solution

Then I came across exim on cygwin. exim is (as it claims to be) a vast improve­ment over the good ol’ send­mail. So I gave it a shot – man, that was awe­some! I can now direct my appli­ca­tion to send to arbi­trary address like [email protected], [email protected] and I can view the results imme­di­ately in a text file, solv­ing the two prob­lems men­tioned above. Here’s what I did:

  • Install exim using cygwin installer
  • Run exim-config
  • Edit /etc/exim.conf
  • Uncom­ment primary_hostname and set it to mail.local
  • Edit the router localuser, com­ment out the line check_local_user (If you don’t know what that means, just search for the line localuser:)
  • Edit %WINDIR%\system32\drivers\etc\hosts, add the line 127.0.0.1 mail.local
  • Finally, reboot the exim service

And there you go! You can now send mail to *@mail.local. To view the mail, go to /var/spool/mail which con­tains all the mail in text files. A simple tail -f /var/spool/mail/foobar can mon­i­tor the mail sent to [email protected]

A simple test to make sure everything’s working:

$ exim -bt [email protected]
[email protected]
  router = localuser, transport = local_delivery
# If something is wrong in your config, it would say "Unrouteable address"
 
# Now let's try sending an email
$ exim -v -odf [email protected]
Hello World!
.
LOG: MAIN
  <= [email protected] U=Chris P=local S=296
delivering KEQKED-0002RS-A7
LOG: MAIN
  => foobar <[email protected]> R=localuser T=local_delivery
LOG: MAIN
  Completed
 
# Cool, let's see if it really delivered
$ tail /var/spool/mail/foobar
Received: from Chris by mail.local with local (Exim 4.69)
        (envelope-from <[email protected]>)
        id KEQKED-0002RS-A7
        for [email protected]; Sun, 08 Feb 2009 15:20:39 +0800
Message-Id: <[email protected]>
From: Chris <[email protected]>
Date: Sun, 08 Feb 2009 15:20:39 +0800
 
Hello World

32 Responses to “cygwin+exim: setting up a local SMTP server for testing email applications”


  • Nice. You men­tion Eclipse here and there, so I assume you also do stuff in Java. Here is one useful library for unit-​testing send­ing emails via SMTP: http://​code.​google.​com/​p​/​s​u​b​e​t​h​a​s​m​t​p​/​w​i​k​i​/​Wiser It acts as SMTP server, and let’s you check received mes­sages in Java code.

  • Interesting. Thanks for the link!

  • How do i use exim to send email with attachment?

  • @Mahesh:

    I don’t know how you can do it from the com­mand line. You prob­a­bly need to use a proper MUA for that, try mutt (avail­able from Cygwin installer). Or you could achieve the same thing with a Perl or Ruby script (more complicated)

  • @Mahesh:

    To send a non-​trivial mail with exim, first format it to a proper rfc822/rfc2822/rfc5322 format mail with the attach­ments done accord­ing to mime (lots of other tools to do that, take your pick), then pass it as input to exim some­thing like this:

    exim -some-options-here-forgot-which < your-message.rfc822

    Exim would do the rest

  • constantly i used to read smaller con­tent which as well clear their motive, and that is also hap­pen­ing with this arti­cle which I am read­ing at this place.

  • I was won­der­ing if you ever thought of chang­ing the page layout of your blog?

    Its very well writ­ten; I love what youve got to say. But maybe you could a little more in the way of con­tent so people could con­nect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?

  • I every time used to study para­graph in news papers but now as I am a user of inter­net so from now I am using net for arti­cles or reviews, thanks to web.

  • Hello, I think your web site may be having inter­net browser com­pat­i­bil­ity prob­lems. When I take a look at your web­site in Safari, it looks fine how­ever, if open­ing in I.E., it has some over­lap­ping issues. I simply wanted to pro­vide you with a quick heads up! Apart from that, won­der­ful blog!

  • Hello, I enjoy read­ing all of your post. I wanted to write a little com­ment to sup­port you.

  • Hello, I think your site could be having web browser com­pat­i­bil­ity issues. When­ever I take a look at your site in Safari, it looks fine how­ever, if open­ing in I.E., it’s got some over­lap­ping issues. I merely wanted to pro­vide you with a quick heads up! Aside from that, excel­lent site!

  • Thank you for the good writeup. It in fact was a amuse­ment account it. Look advanced to more added agree­able from you! How­ever, how could we communicate?

  • You have made some good points there. I looked on the net to learn more about the issue and found most indi­vid­u­als will go along with your views on this web site.

  • I got this web­site from my buddy who informed me regard­ing this web page and now this time I am vis­it­ing this web page and read­ing very infor­ma­tive arti­cles at this place.

  • At this time it appears like Blo­gEngine is the top blog­ging plat­form avail­able right now. (from what I’ve read) Is that what you’re using on your blog?

  • Today, I went to the beach­front with my chil­dren. I found a sea shell and gave it to my 4 year old daugh­ter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  • I loved this post! I read your blog fairly often and you are always coming out with some great stuff. I will shares this on my face­book, insta­gram and some of my loy­alty followers.

    Great jobs! Keep work it with it.

  • you are truly a just right web­mas­ter. The web site load­ing speed is incred­i­ble. It seems that you are doing any unique trick. In addi­tion, The con­tents are mas­ter­work. you’ve done a great process on this subject!

  • I loved this post! I read your blog fairly often and you are always coming out with some great stuff. I will shares this on my face­book, insta­gram and some of my loy­alty fol­low­ers. Great jobs! Keep work it with it.

  • Does your blog have a con­tact page? I’m having trou­ble locat­ing it but, I’d like to shoot you an email. I’ve got some sug­ges­tions for your blog you might be inter­ested in hear­ing. Either way, great web­site and I look for­ward to seeing it grow over time.

  • wonderful points alto­gether, you simply gained a logo new reader. What might you rec­om­mend in regards to your post that you just made some days in the past? Any sure?

  • We stum­bled over here by a dif­fer­ent web page and thought I should check things out. I like what I see so now i am fol­low­ing you. Look for­ward to find­ing out about your web page for a second time.

  • This design is wicked! You obvi­ously know how to keep a resader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fan­tas­tic job.

    I really enjoyed what you had to say, and more than that, how you pre­sented it. Too cool!

  • bookmarked!!, I like your site!

  • Howdy just wanted to give you a quick heads up and let you know a few of the images aren’t load­ing cor­rectly. I’m not sure why but I think its a link­ing issue. I’ve tried it in two dif­fer­ent web browsers and both show the same results.

  • Pretty sec­tion of con­tent. I just stum­bled upon your web­site and in acces­sion cap­i­tal to assert that I acquire in fact enjoyed account your blog posts.

    Any way I will be sub­scrib­ing to your feeds and even I achieve­ment you access con­sis­tently rapidly.

  • fantastic post, very infor­ma­tive. I’m won­der­ing why the other spe­cial­ists of this sector do not notice this. You must con­tinue your writ­ing. I am con­fi­dent, you’ve a great readers’ base already!

  • I am really enjoy­ing the theme/design of your web­site. Do you ever run into any browser com­pat­i­bil­ity prob­lems? A couple of my blog read­ers have com­plained about my web­site not work­ing cor­rectly in Explorer but looks great in Safari. Do you have any advice to help fix this issue?

  • I am curi­ous to find out what blog plat­form you happen to be uti­liz­ing? I’m having some minor secu­rity issues with my latest blog and I would like to find some­thing more safe­guarded. Do you have any suggestions?

  • Its not my first time to pay a visit this web page, i am vis­it­ing this site dailly and take fas­tid­i­ous data from here daily.

  • Potatoes con­tain a good amount of ‘Vitamin C’, when eaten along with the skin. Most people today in our planet are cat­e­go­rized as small shovel indi­vid­u­als. We want it to com­mu­ni­cate directly the target promot.

Leave a Reply