Rails 3 - action mailer SocketError getaddrinfo No such host is known

核能气质少年 提交于 2019-12-08 01:49:11

问题


I've configured the action mailer as per http://edgeguides.rubyonrails.org/action_mailer_basics.html

My Outgoing Mail Server: mail.xxxx.com (server requires authentication) port 26

and i've the following configuration in config\environments\development.rb

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "mail.xxxx.com",
    :port                 => 26,
    :domain               => 'xxxx.com',
    :user_name            => 'dev@xxxx.com',
    :password             => 'dev123',
    :authentication       => 'login',
   # :enable_starttls_auto => true  
  }

But I always get the error

SocketError in AuthController#email_sent

getaddrinfo: No such host is known. 

Rails.root: E:/RailsApps/training_solutions
Application Trace | Framework Trace | Full Trace

app/controllers/auth_controller.rb:9:in `block in email_sent'
app/controllers/auth_controller.rb:7:in `email_sent'
app/controllers/application_controller.rb:35:in `catch_exceptions'

I'm not behind any proxies, and is getting response from mail.xxxx.com when pinging

I'm sure from the log that email is generated correctly, issue is with the delivery of it, please see the log file

DEPRECATION WARNING: RAILS_ROOT is deprecated. Please use ::Rails.root.to_s. (called from block in <class:Plugin> at E:/RailsApps/training_solutions/vendor/plugins/calendar_date_select/init.rb:11)
DEPRECATION WARNING: Use toplevel init.rb; rails/init.rb is deprecated: E:/RailsApps/training_solutions/vendor/plugins/validates_captcha/rails/init.rb. (called from <top (required)> at E:/RailsApps/training_solutions/config/environment.rb:6)
DEPRECATION WARNING: ActionController::Routing::Routes is deprecated. Instead, use Rails.application.routes. (called from <top (required)> at E:/RailsApps/training_solutions/config/routes.rb:1)
DEPRECATION WARNING: You are using the old router DSL which will be removed in Rails 3.1. Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/. (called from <top (required)> at E:/RailsApps/training_solutions/config/routes.rb:1)


Started GET "/auth/email_sent?user[email]=mithun@xxxx.com&user[username]=Mithun" for 127.0.0.1 at 2011-01-03 12:55:51 +0530
  Processing by AuthController#email_sent as HTML
  Parameters: {"user"=>{"email"=>"mithun@xxxx.com", "username"=>"Mithun"}}
  [1m[36mSQL (13.0ms)[0m  [1mdescribe `events_users`[0m
Mysql::Error: Table 'training_solution.events_users' doesn't exist: describe `events_users`
  [1m[35mSQL (4.0ms)[0m  describe `attendances_users`
Mysql::Error: Table 'training_solution.attendances_users' doesn't exist: describe `attendances_users`
  [1m[36mSQL (4.0ms)[0m  [1mdescribe `users_venues`[0m
Mysql::Error: Table 'training_solution.users_venues' doesn't exist: describe `users_venues`
  [1m[35mSQL (1.0ms)[0m  SHOW TABLES
  [1m[36mUser Load (0.0ms)[0m  [1mSELECT `users`.* FROM `users` WHERE (`users`.`id` = 85) LIMIT 1[0m
Rendered emailer/welcome_email.html.erb (0.0ms)
Rendered emailer/welcome_email.text.erb (23.0ms)

Sent mail to mithun@xxxx.com (2524ms)
Date: Mon, 03 Jan 2011 12:55:57 +0530

From: dev@xxxx.com

To: mithun@xxxx.com

Message-ID: <4d217a057af0f_1bb0299d7447683@Mithun-PC.mail>

Subject: Welcome to My Awesome Site

Mime-Version: 1.0

Content-Type: multipart/alternative;

 boundary="--==_mimepart_4d217a0539050_1bb0299d74473e7";

 charset=UTF-8

Content-Transfer-Encoding: 7bit







----==_mimepart_4d217a0539050_1bb0299d74473e7

Date: Mon, 03 Jan 2011 12:55:57 +0530

Mime-Version: 1.0

Content-Type: text/plain;

 charset=UTF-8

Content-Transfer-Encoding: 7bit

Content-ID: <4d217a055bb08_1bb0299d74474d4@Mithun-PC.mail>



Welcome to example.com, Mithun

===============================================



You have successfully signed up to example.com,

your username is: Mithun.



To login to the site, just follow this link: http://example.com/login.



Thanks for joining and have a great day!





----==_mimepart_4d217a0539050_1bb0299d74473e7

Date: Mon, 03 Jan 2011 12:55:57 +0530

Mime-Version: 1.0

Content-Type: text/html;

 charset=UTF-8

Content-Transfer-Encoding: 7bit

Content-ID: <4d217a056d064_1bb0299d74475e9@Mithun-PC.mail>



<!DOCTYPE html>

<html>

  <head>

    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  </head>

  <body>

    <h1>Welcome to example.com, Mithun</h1>

    <p>

      You have successfully signed up to example.com,

      your username is: Mithun.<br/>

    </p>

    <p>

      To login to the site, just follow this link: http://example.com/login.

    </p>

    <p>Thanks for joining and have a great day!</p>

  </body>

</html>



----==_mimepart_4d217a0539050_1bb0299d74473e7--

Caught exception! getaddrinfo: No such host is known. 
Completed   in 3695ms

SocketError (getaddrinfo: No such host is known. ):
  app/controllers/auth_controller.rb:9:in `block in email_sent'
  app/controllers/auth_controller.rb:7:in `email_sent'
  app/controllers/application_controller.rb:35:in `catch_exceptions'

Rendered E:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered E:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.0ms)
Rendered E:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (31.0ms)

What may be the issue


回答1:


Are you trying to generate any urls in your mailer's view?

If so, you'll need to provide a host.

Generating URLs in Action Mailer Views



来源:https://stackoverflow.com/questions/4582759/rails-3-action-mailer-socketerror-getaddrinfo-no-such-host-is-known

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!