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

17 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

  • Unfortunatly exim now requires strange per­mis­sion set­tings and refuses to even start “LOG: MAIN PANIC DIE” “unable to set gid” “setuid for log-​file cre­ation failed, aborting”… I don’t actu­ally care about the log file… there should be no need for chang­ing users/groups it should just open a socket and write emails to files, every­thing else should be an exter­nal OS per­mis­sion issue… this is basic soft­ware devel­op­ment 101… sorry for the rant… just tired of simple pro­grams designed to be impos­si­ble to use.

  • Quality arti­cles is the impor­tant to inter­est the users to visit the web­site, that’s what this site is providing.

  • Spot on with this write-​up, I hon­estly feel this amaz­ing site needs a lot more atten­tion. I’ll prob­a­bly be return­ing to read through more, thanks for the information!

  • SEO is liked by many experts to get suc­cess within the range of market. I just wanted to fig­ured out a means to have the more money pri­vately to cover the bills, or maybe go out to a good dinner once a month or some­thing. There­fore, you’ll want to con­sider using a selec­tion of dif­fer­ent things as soon as pos­si­ble to under­stand what does work and what doesn’t.

  • See, if people are able to find info on your web­site quickly and easily chances are they will require to to pay more hours on your site.

    While red, for instance, will nor­mal­ize yellow, it’ll be hard for it to counter act purple, blue and green all at the same time. In these tech­nol­ogy days, so many indi­vid­u­als are inter­ested to avail these kinds – Aof businesses.

  • Avoid web­site part­ner­ships – Rela­tion­ships all over the net matter.

    The fewer steps you put between prospects as well as the infor­ma­tion you want them to find out, greater you are going to reduce bounce rates. Once you have your arti­cle writ­ten it is pos­si­ble to elect to pub­lish it first your­self web­site before syn­di­cat­ing it round the inter­net on other sites.

  • Thus in dig­i­tal mar­ket­ing there’s con­sid­er­ably more than seiz­ing the traf­fic for that com­pa­nies. Great web­site pages are pro­duced by people who under­stand just what vis­i­tors mean and pro­vide back what exactly they want. The most pop­u­lar is Adobe Pho­to­shop how­ever if you desire some­thing cheaper there are numer­ous suit­able alter­na­tives if you do a little research.

  • Sending a Greet­ing – Did you know that over 150 mil­lion cards are bought on Valentine’s Day. Leather ffor fur­ni­ture could be dyed, stained, waxed, sanded, embossed, and pig­mented per­son­ally to achieve the look and handle thnat the tanner desires.

    Hemp fea­tures a large part of Edes­tin, a price­less kind of pro­tein which sup­ports diges­tion among its many benefits.

  • The game involves cap­tur­ing more Poke­mon and deal­ing with other Poke­mon train­ers when chal­lenged. Analysing this, the game devel­oper has addi­tion­ally pro­duce dif­fer­ent ver­sions along with the dif­fer­ent vol­umes of the sport. The tod­dlers, of course, like to play games and enjoy activ­i­ties that keep these things fascinated.

  • They will con­duct research and devel­op­ment with an entirely new ser­vice which will serve your needs that were unan­swered with the pre­vi­ous prod­uct. One needs to find out some vis­i­ble and never- so vis­i­ble signs around open around the survey web­sites. Here you’ll find infor­ma­tion and com­par­isons of var­i­ous pop­u­lar opportunities.

  • A pas­sion­ate reader could pro­duce a mas­sive stock­pile of books, that is easily elim­i­nated using the latest high-​capacity e – Read­ers. If you’re con­sid­er­ing select­ing offer­ing an e – Book to build your list of cus­tomers, then the first ideal would be to take advan­tage of the resources you already have. Now you have got your free e – Book and you just need to upload it on the blog or website.

Leave a Reply