Mailtrap with JRuby

Mailtrap, a mock SMTP server in a few lines of Ruby, doesn’t work with JRuby out of the box. One of its dependencies, the Daemons gem, uses fork which JRuby doesn’t implement as it’s not safe on the JVM:

$ mailtrap start
/work/software/jruby-1.2.0/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in `safefork': fork is unsafe and disabled by default on JRuby (NotImplementedError)

My quick and dirty workaround was to simply ignore the daemon part and instantiate a non-forking instance of mailtrap running in the foreground:

$ jirb
irb(main):002:0> load 'PATH/TO/jruby/lib/ruby/gems/1.8/gems/mailtrap-0.2.1/lib/mailtrap.rb'
=> true
irb(main):003:0>'localhost', 5555, false, '/tmp/mailtrap.log')

You now have a Mailtrap running on port 5555, and see arriving messages right there in your IRB window. That should be enough for simple tests during development.


Tags: , , , , , , , ,

%d bloggers like this: