Send an email from Rails 3 in development mode, offline?

I am developing an application with email capabilities and I would like to send emails to myself locally (for example, I could completely disconnect my development machine from the Internet and still send and receive these test emails, just my computer).

I assume that the Rails application is being sent to the CLI firmware mailfor Mac OS X, but I do not know how to install it.

I want to do this so that I can send an unlimited number of test emails to myself, without worrying about blocking myself from my GMail account or burning a free credit on Sendgrid, etc. or wait for a round-trip message to appear on any server, etc.

Anyone help me with this?

+3
source share
3 answers

Here it is! MockSMTP (for OS X at least)


UPDATE: maybe it's even better: MailCatcher . Since it runs on Ruby / Web, it is platform independent and does not require a license for desktop software. Also, if you use it in Google Chrome, it uses WebSockets to update in real time when a new message arrives! Cool!

+11
source

Use MailCatcher . This is a gem that runs on a local server (localhost: 1080) and displays outgoing emails from a Rails application in a browser-processed email client.

$ gem install mailcatcher
$ mailcatcher
+4

Until I launch OS X, I really work with OS Xers, and we all use sendmailin development. All you have to do is configure it only for your development environment.

In config/environments/development.rb:

AppName::Application.configure do

  # …

  config.action_mailer.delivery_method = :sendmail
  config.action_mailer.sendmail_settings = {
    :location => '/usr/sbin/sendmail',
    :arguments => '-i -t'
  }

end

Then in your email program, you can add a private method to determine who to send email to if you are worried about accidentally sending email to users / random email addresses:

class UserMailer < ActionMailer
  default :from => 'from.email@example.com'

  def welcome(user)
    @user = user
    mail(
      :subject => "Hello World",
      :to => recipient(@user.email)
    )
  end

private

  def recipient(email_address)
    return 'developer.email@example.com' if Rails.env.development?
    email_address
  end

end
+3
source

All Articles