Guides / Ruby on Rails

Test Ruby on Rails emails locally

RustMail is a local SMTP mail catcher. Your Ruby app keeps sending mail the way it does in production, and every message lands in a web UI instead of a real inbox. Four steps, about two minutes.

  1. Start RustMail

    One container, SMTP on port 1025 and the web UI on 8025.

    docker run -p 1025:1025 -p 8025:8025 smyile/rustmail:latest
  2. Point Ruby on Rails at it

    In config/environments/development.rb, send mail to localhost:1025 with no TLS and no credentials.

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      address: "localhost",
      port: 1025
    }
  3. Send a test email

    Then open localhost:8025: the message is already in the inbox, with its HTML, headers and links.

    bin/rails runner 'ActionMailer::Base.mail(from: "[email protected]", to: "[email protected]", subject: "Welcome", body: "Hello from Rails").deliver_now'
  4. Assert on it in CI

    In GitHub Actions, start RustMail, run tests that send mail with the config/environments/development.rb settings from step 2, then fail the job when the email never arrives.

    - name: Start RustMail on localhost:1025
      uses: rustmailapp/rustmail-action@v1
      with:
        mode: start
    
    - name: Run the tests that send mail over SMTP
      run: bin/rails test:system
    
    - name: Fail if the welcome email never arrived
      uses: rustmailapp/rustmail-action@v1
      with:
        mode: assert
        assert-count: 1
        assert-subject: "Welcome"

Good to know

  • The test environment uses delivery_method :test by default; switch it to :smtp for the system tests that should reach RustMail.

Other frameworks

LaravelDjangoNode.jsSpring Boot