Introducing devmail


File under: crystal devmail email pop3 smtp .

Devmail is an SMTP-server and POP3-server combined into one app. It will keep every email you send to it in one single inbox, regardless of who is addressed, until you fetch it using your normal e-mail program. It is meant for developers who need to inspect the mail that their app sends.

Devmail started as a port of Blue Rail’s Post Office, which is written in Ruby, to Crystal-lang. Internally it uses slightly different classes now but you can still clearly recognize the original idea.

How to install

Clone the repostory, compile it with Crystal, and put the resulting executable in /usr/local/bin.

On MacOS that translates to something like this:

$ git clone git@github.com:tijn/devmail.git
$ cd devmail
$ brew install crystal-lang
$ crystal build src/devmail.cr
$ cp devmail /usr/local/bin/

After that you can use the Launchd script (for MacOS) or the SystemD scripts (for Linux) that I included to launch the devmail service on boot or on login. For instructions look at the README.md file in the startup/{launchd,systemd}/ directory which you can find in the repository.

How to send mail (with Rails)

Say you have a Rails application. You could change the configuration in config/environments/development.rb to something like the following code:

Rails.application.configure do
  # [...]

  # Mailer
  config.action_mailer.default_url_options = { host: ENV.fetch('MAILHOST', 'localhost') }
  if ENV.fetch('DEVMAIL_PORT', false)
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = { address: 'localhost', port: ENV['DEVMAIL_PORT'].to_i }
  else
    config.action_mailer.delivery_method = :letter_opener_web
  end

  # [...]
end

This will send all mail to devmail on the port you configured and it won’t bother your colleagues who like to use Ryan Bates’ Letter Opener. You can set the DEVMAIL_PORT variable in a .env file if you use dotenv, or in your .bashrc or even in /etc/environment. Well, you get the idea.

How to receive mail

Just point your Mail.app or Thunderbird to localhost on the port that you set up (the default POP3 port is 110).

Thunderbird Settings