Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Mailtrap: Dummy Ruby SMTP server (ideal for testing ActionMailer)

By Peter Cooper / October 18, 2007


Mailtrap is a "dummy" SMTP server developed in Ruby by Matt Mower. The main use for Mailtrap is to act as an SMTP server that runs locally and can be sent mail which can be inspected for debugging purposes. For example, your Rails application running locally might need to send mail using ActionMailer, and while you want it to go through all of the SMTP motions, you don't want the mail to really be sent.. enter Mailtrap! In this blog post, Matt goes into more details about how Mailtrap works, why it's a good idea, and the motivation behind its development.


  1. Matthijs Langenberg says:

    I love those KISS projects. Going to digg into the code if I've got some spare time today!

  2. Corné - South Africa says:

    Why would you even distribute a picture like this?

    Surely you can be more creative to represent the word `Trap`.

    Animal cruelty is not something to condone!

    Terrible, this alone will deter me from Mailtrap or even give a glance.

  3. Ben says:

    It looks like hyper-sensitivity is not just an American thing.

  4. Mark Wilden says:

    Is this for testing ActionMailer or for testing apps that use ActionMailer? Because it certainly seems great for the former purpose. But I can't see a need if you're testing your app. Basically, you just need to test whether you're calling ActionMailer stuff correctly - you don't need to test ActionMailer itself (unless you're workiing on ActionMailer).


  5. Matt Mower says:

    Mark Wilden: When I'm running in development mode on my laptop I don't want to have to bother configuring an actual SMTP server or bother about the emails and where they end up (e.g. coming in to my mailbox and having to delete them).

    During testing I establish (with the :test mailer) that the emails are correctly generated. When I'm doing local development I just want ActionMailer to think they have been sent okay. That's what Mailtrap is for.

    Mailtrap allows me to use the SMTP configuration for ActionMailer that I am already familiar with from production. I just configure it for localhost port 2525 and start Mailtrap.

    Now I can run in development mode and mails will be sent out as normal and will just collect in a log file.

    If you've already got a local SMTP server (e.g. postfix) configured and are happy filtering or manually deleting the emails then more power to you.

    For someone too lazy to do that (i.e. Me)... there's Mailtrap.



  6. Mark Wilden says:

    Thanks for the explanation, Matt. From AWDw/R (p. 567), I thought people could use :test in development, too. But when you're developing with :smtp, then I can see that Mailtrap would be very useful, indeed.


  7. Alan Brown says:

    this is cool. been using action_mailer_tls and sending everything thru gmail but this'll work

Other Posts to Enjoy

Twitter Mentions