<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>the kiZZ notes &#187; exim</title>
	<atom:link href="http://kizzx2.com/blog/index.php/tag/exim/feed/" rel="self" type="application/rss+xml" />
	<link>http://kizzx2.com/blog</link>
	<description>random stupid ideas from a narcissistic chode</description>
	<lastBuildDate>Thu, 01 Dec 2011 16:25:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>cygwin+exim: setting up a local SMTP server for testing email applications</title>
		<link>http://kizzx2.com/blog/index.php/2009/02/08/cygwinexim-setting-up-a-local-smtp-server-for-testing-email-applications/</link>
		<comments>http://kizzx2.com/blog/index.php/2009/02/08/cygwinexim-setting-up-a-local-smtp-server-for-testing-email-applications/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 07:23:09 +0000</pubDate>
		<dc:creator>kiZZ kiZZ</dc:creator>
				<category><![CDATA[geek stuffs]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[testing email]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://kizzx2.com/blog/?p=132</guid>
		<description><![CDATA[This is mainly a reference 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 applications that send emails. Obviously I don&#8217;t want to be opening a dozen of real email accounts just to test this [...]]]></description>
			<content:encoded><![CDATA[<p>This is mainly a reference for myself in case I forget how to do it later, as it took me a good deal of time to figure out.</p>

<h4>Situation</h4>

<p>I want to <em>unit test</em> applications that send emails. Obviously I don&#8217;t want to be opening a dozen of real email accounts just to test this thing out. Naturally I would want to install an SMTP/POP3/IMAP server on Windows, and there is one free (open source) option that is quite promising &#8211; <a href="http://hmailserver.com">hMailServer</a>. However, it still involves 2 (quite major) inconveniences for my use case:</p>

<ul>
<li>I have to go through the configuration screens to create new users. i.e. if I want to send email to alice@localhost I&#8217;d have to create the user account alice manually</li>
<li>I have to use an email client (like Outlook Express) to connect to the local POP3 server to view the emails. This seems redundant to me, since the files are already stored in my disks, why can&#8217;t I just view them?</li>
</ul>

<h4>The Solution</h4>

<p>Then I came across exim on cygwin. exim is (as it claims to be) a vast improvement over the good ol&#8217; sendmail. So I gave it a shot &#8211; man, that was awesome! I can now direct my application to send to arbitrary address like alice@mail.local, foobar@mail.local and I can view the results immediately in a text file, solving the two problems mentioned above. Here&#8217;s what I did:</p>

<ul>
<li>Install exim using cygwin installer</li>
<li>Run <code>exim-config</code></li>
<li>Edit /etc/exim.conf</li>
<li>Uncomment <code>primary_hostname</code> and set it to <code>mail.local</code></li>
<li>Edit the <em>router</em> <code>localuser</code>, comment out the line <code>check_local_user</code> (If you don&#8217;t know what that means, just search for the line <code>localuser:</code>)</li>
<li>Edit %WINDIR%\system32\drivers\etc\hosts, add the line</li>
</ul>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">127.0.0.1 &nbsp; &nbsp;mail.local</div></td></tr></tbody></table></div>

<ul>
<li>Finally, reboot the exim service</li>
</ul>

<p>And there you go! You can now send mail to &#42;@mail.local. To view the mail, go to <code>/var/spool/mail</code> which contains all the mail in text files. A simple <code>tail -f /var/spool/mail/foobar</code> can monitor the mail sent to <code>foobar@mail.local</code></p>

<p>A simple test to make sure everything&#8217;s working:</p>

<p><pre class="bash" name="code">
$ exim -bt foobar@mail.local
foobar@mail.local
  router = localuser, transport = local_delivery
&#35; If something is wrong in your config, it would say "Unrouteable address"
&nbsp;
&#35; Now let's try sending an email
$ exim -v -odf foobar@mail.local
Hello World!
.
LOG: MAIN
  &lt;= Chris@mail.local U=Chris P=local S=296
delivering KEQKED-0002RS-A7
LOG: MAIN
  =&gt; foobar &lt;foobar@mail.local&gt; R=localuser T=local_delivery
LOG: MAIN
  Completed
&nbsp;
&#35; 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 &lt;Chris@mail.local&gt;)
        id KEQKED-0002RS-A7
        for foobar@mail.local; Sun, 08 Feb 2009 15:20:39 +0800
Message-Id: &lt;EKEQKED-0002RS-A7@mail.local&gt;
From: Chris &lt;Chris@mail.local&gt;
Date: Sun, 08 Feb 2009 15:20:39 +0800
&nbsp;
Hello World
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://kizzx2.com/blog/index.php/2009/02/08/cygwinexim-setting-up-a-local-smtp-server-for-testing-email-applications/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

