Last active
August 29, 2015 13:58
-
-
Save firedev/9966289 to your computer and use it in GitHub Desktop.
MockSMTP/MailCatcher sniffer for your development.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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