Over the past few days I've been going crazy trying to get email delivery to work using RoR. From what I've read, settings look right, I have no clue what is wrong. I'm hoping the community can give me some insight on how to get this thing running.
All testing is done in development environment on port 3000.
Users must follow the link emailed to them in order to activate an account.
If I set "config.action_mailer.raise_delivery_errors = false" everything appears to work fine, but the email doesn't get sent. (log shows the email was sent to the correct address, activation link works fine). Once set to true I get a refused connection. Bellow is actual code from each email related file, error details at the end.
environment.rb: config.active_record.observers = :user_observer config.action_mailer.delivery_method = :smtp
development.rb: config.action_mailer.raise_delivery_errors = true config.action_mailer.default_charset = "utf-8" config.action_mailer.perform_deliveries = true config.action_mailer.default_content_type = "text/html"
mailsetup.rb: # Load mail configuration if not in test environment if RAILS_ENV != 'test' email_settings = YAML::load(File.open("#{RAILS_ROOT}/config/ email.yml")) ActionMailer::Base.smtp_settings = email_settings[RAILS_ENV] unless email_settings[RAILS_ENV].nil? end
email.yml: development: address: "shawmail.wp.shawcable.net" port: 25 domain: "shaw.ca" authentication: :login user_name: "....@shaw.ca" password: "secret"
production: address: "shawmail.wp.shawcable.net" port: 25 domain: "shaw.ca" authentication: :login user_name: "....@shaw.ca" password: "secret"
test: address: smtp.gmail.com port: 587 domain: "gmail.com" authentication: :login user_name: ....@gmail.com password: secret
account_controller.rb : def signup @title = "Sign Up" @user = User.new(params[:user])
return unless request.post? @user.btn1 = "Default" @user.btn2 = "Default" @user.btn3 = "Default" @user.save! #<-- this is line 99
redirect_back_or_default( :action => 'welcome')
rescue ActiveRecord::RecordInvalid render :action => 'signup' end
user_observer.rb: class UserObserver < ActiveRecord::Observer def after_create(user) UserNotifier.deliver_signup_notification(user) end
def after_save(user) UserNotifier.deliver_activation(user) if user.recently_activated? end end
user_notifier: class UserNotifier < ActionMailer::Base def signup_notification(user) setup_email(user) @subject += ' account activation' @body[:url] = "http://localhost:3000/account/activate/# {user.activation_code}" end
def activation(user) setup_email(user) @subject += ' ' @body[:url] = "http://localhost:3000/" end
protected def setup_email(user) @recipients = "#{user.email}" @from = "admin" @subject = "Controllers" @sent_on = Time.now @body[:user] = user end end
Error: Errno::ECONNREFUSED (No connection could be made because the target machine actively refused it. - connect(2)): C:/Ruby/lib/ruby/1.8/net/protocol.rb:206:in `initialize' C:/Ruby/lib/ruby/1.8/net/protocol.rb:206:in `new' C:/Ruby/lib/ruby/1.8/net/protocol.rb:206:in `old_open' C:/Ruby/lib/ruby/1.8/timeout.rb:62:in `timeout' C:/Ruby/lib/ruby/1.8/timeout.rb:93:in `timeout' C:/Ruby/lib/ruby/1.8/net/protocol.rb:206:in `old_open' C:/Ruby/lib/ruby/1.8/net/smtp.rb:392:in `do_start' C:/Ruby/lib/ruby/1.8/net/smtp.rb:377:in `start' C:/Ruby/lib/ruby/1.8/net/smtp.rb:315:in `start' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/ action_mailer/base.rb:628:in `perform_delivery_smtp' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/ action_mailer/base.rb:508:in `__send__' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/ action_mailer/base.rb:508:in `deliver!' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/ action_mailer/base.rb:383:in `method_missing' /app/models/user_observer.rb:3:in `after_create' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/observer.rb:171:in `send' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/observer.rb:171:in `update' C:/Ruby/lib/ruby/1.8/observer.rb:185:in `notify_observers' C:/Ruby/lib/ruby/1.8/observer.rb:184:in `each' C:/Ruby/lib/ruby/1.8/observer.rb:184:in `notify_observers' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/callbacks.rb:309:in `notify' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/callbacks.rb:296:in `callback' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/callbacks.rb:221:in `create_without_timestamps' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/timestamp.rb:29:in `create' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/base.rb:2483:in `create_or_update_without_callbacks' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/callbacks.rb:207:in `create_or_update' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/base.rb:2217:in `save_without_validation!' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/validations.rb:921:in `save_without_dirty!' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/dirty.rb:83:in `save_without_transactions!' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/transactions.rb:110:in `save!' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/connection_adapters/abstract/database_statements.rb: 66:in `transaction' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/transactions.rb:79:in `transaction' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/transactions.rb:98:in `transaction' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/transactions.rb:110:in `save!' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/transactions.rb:118:in `rollback_active_record_state!' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/transactions.rb:110:in `save!' /app/controllers/account_controller.rb:99:in `signup' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/base.rb:1166:in `send' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/base.rb:1166:in `perform_action_without_filters' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/filters.rb:579:in `call_filters' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/filters.rb:572:in `perform_action_without_benchmark' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/benchmarking.rb:68:in `perform_action_without_rescue' C:/Ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/benchmarking.rb:68:in `perform_action_without_rescue' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/rescue.rb:201:in `perform_action_without_caching' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/caching/sql_cache.rb:13:in `perform_action' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/connection_adapters/abstract/query_cache.rb:33:in `cache' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/ active_record/query_cache.rb:8:in `cache' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/caching/sql_cache.rb:12:in `perform_action' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/base.rb:529:in `send' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/base.rb:529:in `process_without_filters' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/filters.rb:568:in `process_without_session_management_support' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/session_management.rb:130:in `process' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/base.rb:389:in `process' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/dispatcher.rb:149:in `handle_request' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/dispatcher.rb:107:in `dispatch' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/dispatcher.rb:104:in `synchronize' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/dispatcher.rb:104:in `dispatch' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/dispatcher.rb:120:in `dispatch_cgi' C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/dispatcher.rb:35:in `dispatch' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../ lib/mongrel/rails.rb:76:in `process' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../ lib/mongrel/rails.rb:74:in `synchronize' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../ lib/mongrel/rails.rb:74:in `process' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:159:in `process_client' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:158:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:158:in `process_client' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:285:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:285:in `initialize' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:285:in `new' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:285:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:268:in `initialize' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:268:in `new' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel.rb:268:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel/configurator.rb:282:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel/configurator.rb:281:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel/configurator.rb:281:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/ mongrel_rails:128:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/ mongrel/command.rb:212:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/ mongrel_rails:281 C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:503:in `load' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:503:in `load' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:355:in `new_constants_in' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:503:in `load' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/servers/ mongrel.rb:64 C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:510:in `require' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:355:in `new_constants_in' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/ active_support/dependencies.rb:510:in `require' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb: 39 C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' script/server:3
Rendering C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/ action_controller/templates/rescues/layout.erb (internal_server_error)