alexp
January 24, 2006, 5:57pm
1
Hi, I’ve setup Action Mailer today to email the contents of a form.
Every seemes fine except when the email is sending.
Here is the error I get on the production server:
SocketError (getaddrinfo: Name or service not known):
/usr/lib/ruby/1.8/net/protocol.rb:83:in initialize' /usr/lib/ruby/1.8/net/protocol.rb:83:in
new’
/usr/lib/ruby/1.8/net/protocol.rb:83:in connect' /usr/lib/ruby/1.8/net/protocol.rb:82:in
timeout’
/usr/lib/ruby/1.8/timeout.rb:62:in timeout' /usr/lib/ruby/1.8/net/protocol.rb:82:in
connect’
/usr/lib/ruby/1.8/net/protocol.rb:64:in initialize' /usr/lib/ruby/1.8/net/smtp.rb:393:in
open’
/usr/lib/ruby/1.8/net/smtp.rb:393:in do_start' /usr/lib/ruby/1.8/net/smtp.rb:378:in
start’
/usr/lib/ruby/1.8/net/smtp.rb:316:in start' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:436:in
perform_delivery_smtp’
/usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:327:in
send' /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:327:in
deliver!’
/usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:223:in
method_missing' /app/controllers/email_controller.rb:8:in
sent’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
perform_action_without_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in
perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in
perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
send’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in
process’
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/fcgi_handler.rb:141:in
process_request’
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/fcgi_handler.rb:53:in
process!' /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/fcgi_handler.rb:52:in
each_cgi’
/usr/lib/ruby/1.8/fcgi.rb:597:in each' /usr/lib/ruby/1.8/fcgi.rb:597:in
each_cgi’
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/fcgi_handler.rb:52:in
process!' /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/fcgi_handler.rb:22:in
process!’
dispatch.fcgi:24
It does do this before it though Processing EmailController#sent (for
84.12.155.53 at 2006-01-24 08:50:41) [POST] So the code generating the
email is fine.
I would really appreciate any help!!
alexp
January 24, 2006, 6:05pm
2
Hi Alex ~
I have posted this before, but it might help. In this configuration the
smtp server is on the same server as the app. This works in both my
production and development environment.
Here is an example of all the “pieces” to get actionmailer working.
rails_root/config/environment.rb
ActionMailer::Base.server_settings = {
:address => "localhost",
:port => 25,
}
rails_root/app/controllers/my_controller.rb
def test_message_send
Notifier::sendtest()
end
rails_root/app/models/notifier.rb
class Notifier < ActionMailer::Base
def sendtest()
@recipients = "[email protected] "
@from = "[email protected] "
@subject = "Subject"
@body["first_name"] = "first_test"
@body["last_name"] = "last_test"
end
end
rails_root/app/views/notifier/sendtest.rhtml
Hello <%= @first_name %> <%= @last_name %>,
Test Msg...
alexp
January 24, 2006, 6:05pm
3
When I read the subject on this, I thought the body was going to be -
Is still a better day than mailing in PHP/ASP/Perl.
matt
alexp
January 24, 2006, 6:07pm
4
Thanks Ben R.,
I’ll give that a try now.
alexp
January 24, 2006, 6:29pm
5
Hi Alex ~
I don’t think all your variables need to be @ variables… When you call
your mailer object, try:
mail = params[‘mail’]
name = params[‘name’]
text = params[‘text’]
Mail::sendtest(mail, name, text)
alexp
January 24, 2006, 6:33pm
6
Okay did that and now I have
NoMethodError in Email#test_message
undefined method sendtest' for Mail:Class RAILS_ROOT: /Users/alexp/Sites/pulse/script/../config/.. Application Trace | Framework Trace | Full Trace /usr/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer/base.rb:225:in
method_missing’
#{RAILS_ROOT}/app/controllers/email_controller.rb:8:in `test_message’
I dont think it likes that sendtest method very much.
alexp
January 24, 2006, 6:38pm
7
Alex ~
Have you restarted your app lately? I have had some instances where
changes
where not picked up on my mailer model… Worth a shot.
~ Ben
alexp
January 24, 2006, 6:23pm
8
I cant get past this error now
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.sendtest
RAILS_ROOT: /Users/alexp/Sites/pulse/script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/email_controller.rb:8:in `test_message’
my controller is this
class EmailController < ApplicationController
def index
end
def test_message
@mail = @params [‘mail’]
@name = @params [‘name’]
@text = @params [‘text’]
@Mail ::sendtest(@mail , @name , @text )
end
end
my mail.rb is this
class Mail < ActionMailer::Base
def sendtest(mail, name, text)
@recipients = “[email protected] ”
@from = “[email protected] ”
@subject = “Subject”
@body['text'] = text
@body['name'] = name
@body['mail'] = mail
end
end
alexp
January 24, 2006, 6:41pm
9
On 1/24/06, Alexander P. [email protected] wrote:
I dont think it likes that sendtest method very much.
Please include the previous messages that you are replying to.
What the heck is Mail::sendtest?
Try Mail::deliver_sendtest.
Read Peak Obsession and
brush up on your Ruby.
alexp
January 24, 2006, 6:43pm
10
Ben R. wrote:
Alex ~
Have you restarted your app lately? I have had some instances where
changes
where not picked up on my mailer model… Worth a shot.
~ Ben
Yeah I’ve been doing that alot, didn’t change anything.
I’m quite dissapointed with the documentation on ActionMailer. There are
no decent examples on the subject.
alexp
January 24, 2006, 6:45pm
11
Joe Van D. wrote:
On 1/24/06, Alexander P. [email protected] wrote:
I dont think it likes that sendtest method very much.
Please include the previous messages that you are replying to.
What the heck is Mail::sendtest?
Try Mail::deliver_sendtest.
Read Peak Obsession and
brush up on your Ruby.
I’ve been working on it all day, Mail::deliver_sendtest. is what I used
at the start then I was advised to change it so I did.
alexp
January 24, 2006, 6:48pm
12
Joe Van D. wrote:
On 1/24/06, Alexander P. [email protected] wrote:
I dont think it likes that sendtest method very much.
Please include the previous messages that you are replying to.
What the heck is Mail::sendtest?
Try Mail::deliver_sendtest.
Read Peak Obsession and
brush up on your Ruby.
I changed it back to deliver_sendtest now and it works. My problem was
with the smtp server in the end it seems. Although I haven’t tested it
in production yet and that’s where I had the problem.
alexp
January 24, 2006, 6:51pm
13
Joe is correct, need to update my example. You want to call the deliver
method.
alexp
January 24, 2006, 7:05pm
14
Ben R. wrote:
Joe is correct, need to update my example. You want to call the deliver
method.
Thanks again guys.
And for your information, you still need to use
@mail = @params [‘mail’]
@name = @params [‘name’]
@text = @params [‘text’]
Or it doesn’t work.
alexp
January 24, 2006, 7:30pm
15
On 1/24/06, Alexander P. [email protected] wrote:
Ben R. wrote:
Joe is correct, need to update my example. You want to call the deliver
method.
Thanks again guys.
And for your information, you still need to use
@mail = @params [‘mail’]
@name = @params [‘name’]
@text = @params [‘text’]
er, I assume this is in the controller.
def YourController < AC
def a_method
mail = params[‘mail’]
name = params[‘name’]
text = params[‘text’]
Mail::deliver_sendtest(mail, name, test)
end
end
That should work fine. There’s no need to create controller instance
variables.