简体   繁体   中英

No route to host - connect(2) (Errno::EHOSTUNREACH)

Where can i find configuration to the SMTP server?

**************/usr/lib/ruby/1.8/net/smtp.rb:551:in `initialize': No 
route to host - connect(2) (Errno::EHOSTUNREACH)
 from 
/usr/lib/ruby/1.8/net/smtp.rb:551:in `open'
 from 
/usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
 from 
/usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
 from 
/usr/lib/ruby/1.8/timeout.rb:101:in `timeout'
 from 
/usr/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
 from 
/usr/lib/ruby/1.8/net/smtp.rb:525:in `start'
 from 
/usr/lib/ruby/gems/1.8/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in 
`deliver!'
 from 
/usr/lib/ruby/gems/1.8/gems/mail-2.5.4/lib/mail/message.rb:248:in 
`deliver!'

The error Errno::EHOSTUNREACH: No route to host - connect(2) indicates a routing problem and has probably something to do with a wrong IP address. You might have specified a wrong IP in /etc/hosts (the hosts file which maps hostnames to IP addresses) or elsewhere, for instance in config/deploy.rb, etc.. If you use a local network with a DHCP server, the IP adresses can change frequently.

begin
  # problematic code
rescue Errno::EHOSTUNREACH
  # log the error
  # let the User know
rescue
  # handle other exceptions
end

You appear to be using the Ruby "Mail" library : http://rubygems.org/gems/mail

From my reading of the documentation, there is no configuration file. Instead, the library (optionally) configured in Ruby code.

If you don't do any configuration, the library defaults to using the mail server that is listening on "localhost" port 25. In that case, a "EHOSTUNREACH: No route to host" error most likely means that:

  • your computer either has a bad "hosts" entry for "localhost", or

  • the local host IP device is not properly configured.

Either way, is a system management problem not a programming problem. That's off-topic for SO ... and you haven't provided enough information to help us to diagnose / solve it anyway.

Otherwise, your code will somewhere contains something like this:

Mail.defaults do
  delivery_method :smtp, { :address => "smtp.me.com",
                           :port => 587,
                           :domain => 'your.host.name',
                           :user_name => '<username>', 
                           :password => '<password>',
                           :authentication => 'plain',
                           :enable_starttls_auto => true }
end

The problem will be that the ":address" entry is pointing to a server that you can't talk to. If the entry has the wrong value in it, fix it. Otherwise this is a system (or network) management problem, not a programming problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM