Skip to content

Instantly share code, notes, and snippets.

@firedev
Last active August 29, 2015 13:58
Show Gist options
  • Save firedev/9966289 to your computer and use it in GitHub Desktop.
Save firedev/9966289 to your computer and use it in GitHub Desktop.
MockSMTP/MailCatcher sniffer for your development.rb
# config/environments/development.rb
require "net/smtp" # don't forget to add this first
# Try to sniff out if MockSMTP or MailCatcher is running
begin
smtp = Net::SMTP.start "localhost", 1025
if smtp.started?
smtp.quit
puts ">> Emails WILL be sent to the SMTP server on port 1025"
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
config.action_mailer.raise_delivery_errors = true
end
rescue Errno::ECONNREFUSED
puts ">> Emails will be sent to STDOUT"
config.action_mailer.raise_delivery_errors = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment