<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:ent="http://www.purl.org/NET/ENT/1.0/">
  <channel>
    <title>Curiouser and Curiouser! on smtp</title>
    <link>http://matt.blogs.it/</link>
    <description>RSS feed for topic smtp</description>
    <copyright>Copyright 2007 Matt Mower. Some rights reserved.</copyright>
    <generator>Squib/0.5.0.382</generator>
    <managingEditor>self@mattmower.com</managingEditor>
    <webMaster>self@mattmower.com</webMaster>
    <language>en-gb</language>
    <item>
      <title>Mailtrap</title>
      <link>http://matt.blogs.it/entries/00002655.html</link>
      <pubDate>Thu, 04 Oct 2007 11:28:37 +0100</pubDate>
      <description>&lt;p&gt;Rails comes with a useful library for generating emails called &lt;a href="http://wiki.rubyonrails.org/rails/pages/ActionMailer"&gt;ActionMailer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;ActionMailer has three delivery modes test, sendmail, and smtp. SMTP is what, by and large, everybody uses but who wants to setup a local SMTP server for testing &amp;amp; development when you don't really want to deliver the email anyway? Even thinking about sendmail makes me shudder and the test delivery method just sticks the things in an array that you then need to deal with. That's fine in a test case but you don't want code for that in your app.&lt;/p&gt;

&lt;p&gt;Yesterday I mocked up  the simplest, dumbest, Ruby SMTP server you can imagine. It's called &lt;a href="http://rubymatt.rubyforge.org/mailtrap/"&gt;Mailtrap&lt;/a&gt; and that's exactly what it does. It let's SMTP clients come and send it their email then it dumps the email into a sequentially numbered file for you.&lt;/p&gt;

&lt;p&gt;Mailtrap has, essentially, zero configuration. By default it creates an SMTP server on &lt;code&gt;localhost&lt;/code&gt; port &lt;code&gt;2525&lt;/code&gt; that writes messages into &lt;code&gt;/var/tmp&lt;/code&gt;. You can be up and running with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  sudo gem install -y mailtrap
  mailtrap start
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;then just configure your ActionMailer for development (using config/environment/development.rb) settings as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :domain =&amp;gt; "mydomain.net",
  :address =&amp;gt; "localhost",
  :port =&amp;gt; 2525,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and you're good to go. Messages will accumulate in &lt;code&gt;/var/tmp&lt;/code&gt; in numbered files starting from &lt;code&gt;smtp0001.msg&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Mailtrap was written to fit with ActionMailer but it might also be useful for testing other types of SMTP client. However it's pidgeon-SMTP might let it down for that. YMMV.&lt;/p&gt;

&lt;p&gt;Released under an MIT license and with the assistance of &lt;a href="http://seattlerb.rubyforge.org/hoe/"&gt;Hoe&lt;/a&gt; and &lt;a href="http://codeforpeople.rubyforge.org/rubyforge/"&gt;Rubyforge&lt;/a&gt;.&lt;/p&gt;</description>
      <guid isPermaLink="true">http://matt.blogs.it/entries/00002655.html</guid>
      <ent:cloud ent:href="http://matt.blogs.it/topics/">
      </ent:cloud>
    </item>
  </channel>
</rss>
