問題描述
在說 smtp.start 時獲取“initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError)” (Getting "
initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError)" when saying smtp.start)
I'm trying to send an email using my gmail in a very simple ruby script. This is the part that is supposed to send an email to RECEIVER
from SENDER
which is me. For PASSWD
I use my gmail password.
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start('gmail.com', SENDER, PASSWD, :login)
smtp.send_message message, SENDER, RECEIVER
smtp.finish
Now, I always get this error:
/Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/net/smtp.rb:540:in `initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError)
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/net/smtp.rb:540:in `open'
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/net/smtp.rb:549:in `block in do_start'
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/net/smtp.rb:549:in `do_start'
from /Users/David/.rvm/rubies/ruby‑1.9.3‑p374/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
The weird thing is that it worked one or two days ago and I didn't change the script.
I did update Ruby and Rails, though, within the last two days and I'm not sure if I tested the script before or after the update. Could that be related?
Does anyone have an idea what's going on here and a possible solution?
‑‑‑‑‑
參考解法
方法 1:
I'll answer my question here so it doesn't appear as unanswered since I found out what caused this error.
So, just after posting this question I realized that I had accidentally blocked access to smtp.google.com in Hands Off! My bad. So, this issue is solved now and everything works like it should.
(by dschwertfeger、dschwertfeger)