ActionMailer 2.0.2 NameError

Jonathon Davis-2 wrote:

I'm having a problem with ActionMailer on Rails 2.0.2.

app/config/environment.yml

----------------------

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
    :address => "my.server.address.com",
    :port => 25,
    :domain => "my.server.domain.com",
    :authentication => :login,
    :user_name => "test_mailer@my.server.domain.com",
    :password => "my_password"
  }

And here's my output:

=> Booting WEBrick...
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/
dependencies.rb:266:in `load_missing_constant': uninitialized constant
ActionMailer (NameError)
        from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:453:in `const_missing'
        from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:465:in `const_missing'
        from C:/InstantRails/rails_apps/rails_space/config/
environment.rb:64
        from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/
initializer.rb:47:in `run'
        from C:/InstantRails/rails_apps/rails_space/config/
environment.rb:13
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
        from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:496:in `require'
         ... 8 levels...
        from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/
server.rb:39
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
        from script/server:3
Any assistance would be greatly appreciated.

Hey guys, I had this problem as well, I searched around a bit in the
base.rb(X:\ruby\libs\ruby\gems\1.8\gems\actionmailer-2.0.2\lib\action_mailer\base.rb)
and found the problem(for me anyhow). Instead of
"ActionMailer::Base.server_settings = { .. ect .." they have it defined as
"ActionMailer::Base.smtp_settings = { .. ect .." to define our smtp servers
parameters.

Taken directly from base.rb:

  # * <tt>smtp_settings</tt> - Allows detailed configuration for :smtp
delivery method:
  # * <tt>:address</tt> Allows you to use a remote mail server. Just
change it from its default "localhost" setting.
  # * <tt>:port</tt> On the off chance that your mail server doesn't run
on port 25, you can change it.
  # * <tt>:domain</tt> If you need to specify a HELO domain, you can do it
here.
  # * <tt>:user_name</tt> If your mail server requires authentication, set
the username in this setting.
  # * <tt>:password</tt> If your mail server requires authentication, set
the password in this setting.
  # * <tt>:authentication</tt> If your mail server requires
authentication, you need to specify the authentication type here.

As for where to place it definitely create it it's own file in the
initializers directory with your connection info, and not at the end of the
environment.rb (\yourapp\config\initializers\action_mailer.rb)

Here is what the file(action_mailer.rb) should look like:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "localhost", # or an external ip if your using a remote smtp
   :port => 25,
   :domain => "domainnamehere",
   :authentication => :login,
   :user_name => "username here",
   :password => "passwordhere"
}

Cheers, Ziggah