ActionMailer 2.0.2 NameError

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

app/config/environment.yml

I appreciate your reply. I moved it out of the block, and it gave me
the same error. I also moved it to my environment/development.yml file
and it still did not work. I do see what you're saying though, that
it's trying to call it before it's initialized. Is there any other
place I could put it that would ensure that it gets called after it
has initialized ActionMailer?

Thanks

I made sure the line was commented out, as it was by default.

Thanks for your help

I'm having the same issue, trying to setup mail first time. Do you
have any solution yet ?

Here is my stacktrace,

C:/projects/Sample/config/environments/development.rb:23:in
`load_environment': undefined local variable or method `smtp' for
#<Rails::Initializer:0x2b01740> (NameError)

        from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/
initializer.rb:206:in `load_environment'

Any help will be appreciated.

Thanks.

Hi guys,

In Rails 2.0 you should put configuration into their own specific files in the initializers/ directory. Create a action_mailer.rb file in initializers/ and then specify your ActionMailer settings within. Rails 2.0 loads all files found in the initializers/ directory when the framework initializes.

By the way, if you are sending your mail from an smtp host other than your deploy machine, specify the settings as follows:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => “my.server.address.com”, # => EXTERNAL SMTP HOST
:port => 25,
:domain => “my.server.domain.com”,
:authentication => :login,
:user_name => “test_mailer@my.server.domain.com”,
:password => “my_password”
}

But if your deploy machine is doing the smtp work then make sure you specify localhost as the address, like so:

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

Hopefully this may solve your ActionMailer woes…

Maruis Marais

Freelance Software Developer

Email: maruis@xtra.co.nz

maruis.marais@gmail.com

Web: http://www.exceptionz.com

Blog: http://exceptionz.wordpress.com

Tel: +64 (0) 9 815 9273 (home)

+64 (21) 736 070 (mobile)

I have put the ActionMailer settings code in the end of
config/environment.rb file. I am in Forget password option and want to
mail user's credentials to his mail address but when i click the button,
it shows me the following error and mail is not sent:

Net::SMTPAuthenticationError in SessionsController#create

502 unimplemented (#5.5.1)

RAILS_ROOT: C:/work/2phone
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/1.8/net/smtp.rb:577:in `auth_plain'
c:/ruby/lib/ruby/1.8/net/smtp.rb:571:in `__send__'
c:/ruby/lib/ruby/1.8/net/smtp.rb:571:in `authenticate'
c:/ruby/lib/ruby/1.8/net/smtp.rb:411:in `do_start'
c:/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start'
c:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:586:in
`perform_delivery_smtp'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:469:in
`__send__'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:469:in
`deliver!'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:352:in
`method_missing'
app/controllers/sessions_controller.rb:44:in `forgetpassword'
app/controllers/sessions_controller.rb:22:in `create'

I have put the ActionMailer settings code in the end of
config/environment.rb file. I am in Forget password option and want to
mail user's credentials to his mail address but when i click the button,
it shows me the following error and mail is not sent:

Net::SMTPAuthenticationError in SessionsController#create

502 unimplemented (#5.5.1)

RAILS_ROOT: C:/work/2phone
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/1.8/net/smtp.rb:577:in `auth_plain'
c:/ruby/lib/ruby/1.8/net/smtp.rb:571:in `__send__'
c:/ruby/lib/ruby/1.8/net/smtp.rb:571:in `authenticate'
c:/ruby/lib/ruby/1.8/net/smtp.rb:411:in `do_start'
c:/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start'
c:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:586:in
`perform_delivery_smtp'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:469:in
`__send__'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:469:in
`deliver!'
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:352:in
`method_missing'
app/controllers/sessions_controller.rb:44:in `forgetpassword'
app/controllers/sessions_controller.rb:22:in `create'

Shikha Sharma wrote:

I have put the ActionMailer settings code in the end of
config/environment.rb file. I am in Forget password option and want to
mail user's credentials to his mail address but when i click the button,

Storing passwords as plaintext is bad. Reset the password to something
you know and send out, or, better yet, generate a one-time link to send
off to the user, together with another type of authentication that was
set, like providing the answer to a user-defined question.

Email is not safe enough to send passwords, and it is incredibly lax of
you/your team to store passwords unencrypted.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

Take care to branch the right way on equality.
~ - The Elements of Programming Style (Kernighan & Plaugher)

Phillip Gawlowski wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Storing passwords as plaintext is bad. Reset the password to something
you know and send out, or, better yet, generate a one-time link to send

Hey passwords are stored in encrypted form using

Digest::SHA1.hexdigest("--#{salt}--#{password}--")

but i want the way how i can decrypt it and also want your help in
sending a mail. i have posted the error which was there. please send me
reply of that too, thanks.

Shikha Sharma wrote:

Phillip Gawlowski wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Storing passwords as plaintext is bad. Reset the password to something
you know and send out, or, better yet, generate a one-time link to send

Hey passwords are stored in encrypted form using

Digest::SHA1.hexdigest("--#{salt}--#{password}--")

A hash is one way. There is no way to recreate a hash, especially not
one that is salted.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

~ - You know you've been hacking too long when...
...your children do something they shouldn't do, you tell them to stop, they
do it just once more anyway, so you think "Well, they prefetched the
instruction and are executing it in the delay slot."

Thanks for the info.. after i paste the code outside of the block, it
worked for me.