Help please with email

I'm attempting to get email working and I should mention in Development. Generating some errors and hope some one might catch my mistake.

Controller call: def register u =[:user]) @session['user'] = RegMailer.deliver_greeting(u) # this is the line that's throwing the error - redirect_to :controller => "main", :action => "welcome"

Here is the error: undefined local variable or method `user' for #<RegMailer:0x36c2f58>

RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/models/reg_mailer.rb:14:in `greeting' #{RAILS_ROOT}/app/controllers/main_controller.rb:7:in `register'

Here is the mailer: class RegMailer < ActionMailer::Base   def greeting(sent_at =     @subject = 'Thank you for registering'     @body["first_name"]= user.first_name     @recipients["email"] =     @from = ''     @sent_on = sent_at   end end

Here is the view: Dear <%= @u.first_name %> Thank you for signing up at our webiste.

I'm not even sure why the argument to def greeting is "sent_at =" I went along with the same from AWDWR. Where in just setting up an email in Ruby and ActionMailer I sent mail using def simple_message(recipient) which seemed to work.


Hmmm....still aggrevating me with a new error:

"NoMethodError in MainController#register You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occured while evaluating nil.="

Here is the mailer def greeting(user)     @subject = 'Thank you for registering'     @body["first_name"]= user.first_name     @recipients["email"] =     @from = '****@*****.com'     @sent_on = sent_at   end

and the action : def register     u =[:user])     @session['user'] =     RegMailer.deliver_greeting(u) <--------------ACTION for Mailer     redirect_to :controller => "main", :action => "welcome"   end


I think I'm almost there but down it's bombing on :

SocketError in MainController#register

getaddrinfo: no address associated with hostname.

Everything seems to be in order From config/environments/development.rb:

# Base delivery ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.server_settings = {     :address => "mail.******.com",     :port => 25,     :domain => "*****.com",     :authentication => :login,     :user_name => "**********",     :password => "**********" }

ActionMailer::Base.default_charset = "utf-8"

These are the correct settings for my smtp server (minus what's blanked by asterix)


I don't know if that's true, from what I read you configure in the development config file and then should be allowed to send my mail through and SMTP server. I've done it via regular Ruby program with ActionMailer not sure why Rails would be any different.

Right now I'm still getting : getaddrinfo: no address associated with hostname.

Anyone have any ideas why ? Everything looks fine in the config file.


Thanks Michael, I'll play around with the settings as you suggest. I still wonder if something else within Rails is causing the issue. My Ruby email program has the same settings as the environment.rb in Rails, except that from what I see Rails uses double quotes, and the Ruby has single quotes around the parameter. Didn't seem to matter much though.


Stuart - one more thing to think about... may be your incoming server name - not the outgoing server name. Mine is Maybe this isn't the case since you have it working elsewhere but just a thought.



I just got back to working on this and did a registration to test. This time the getaddrinfo error wasn't thrown, but I haven't seen an email come through either. I opened the development log and saw this:

Sent mail:

Haven't seen a reply come through so I'm throwing this out again. Not sure what the code issues are but I want to send an email when a new user registers. I'm capturing their information in the variable u and that works for database entry. Problem is passing it over to the mailer. I'm guess becuase u is a local it's not making it across to the mailer. From the log the email is working but it says it went to :slight_smile:

Would like some suggestions maybe.

I made all the syntax corrections and now the development log shows it's being sent to the correct email address. Still no email is coming through and so now I'm wondering if it's a configuration issue with ActionMailer. I believe that in order to actually use mailers in development mode you make all the specific configurations in config/environments/development.rb which I've done. I went ahead to make sure that i could connect to my remote smtp server via a Ruby program. Again the Ruby program sends the mail (and it's using ActionMailer). Rails though is not sending the email ?


I also want to add that I put the configuration in environment.rb as well. Still no change. Stuart

One more thing : I've set the following line (instead of default) config.action_mailer.raise_delivery_errors = true and not seeing any errors in dev log.


bump! sorry this is driving me nuts, development log say mail is sending ,but the mail is not coming through. Just to review here I've set ActionMailer configuration options in config/environments/development.rb.

# I want to see errors raised config.action_mailer.raise_delivery_errors = true

# Base delivery ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.server_settings = {     :address => "",     :port => 25,     :domain => "",     :user_name => "myusername",     :password => "mypassword",     :authentication => :login }

ActionMailer::Base.default_charset = "utf-8"

Just to show what's in the dev log:

e[4;35;1mSQL (0.078000)e[0m e[0mCOMMITe[0m Sent mail:

Wait here is something weird! I started thinking maybe something is wrong with the local server (webrick) and considered trying mongrel. However instead of loading up the app in firefox via webrick and just run it in RadRails under port 3003. Trying to register 3 x I get recognition errors. Very odd since things were working right before. 4th time registration succeeds and the email goes through.

So it's got to be something in my browser (only thing I can think of). Though I'm not entirely sure what browser RadRails is using. Then there is the weirdness of the browser inside RadRails giving me routing errors (recognition).

Oiiiiiiiiiiiii! Stuart


What do you get in the console?

script/console RegMailer.deliver_greeting( User.find_by_id( your_id ) )

If you get something like #<TMail::Mail port=#<TMail::StringPort:id=0x11b3e3e>

then it's most likely something outside of your app. I'm thinking
your ISP doesn't allow that sort of traffic. If that's the problem,
you can get around it if your host allows mail to be sent on an
alternate port (!= 25). I know Dreamhost allows that sort of