在說 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)


問題描述

在說 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 RECEIVERfrom SENDER which is me. For PASSWDI 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 dschwertfegerdschwertfeger)

參考文件

  1. Getting "`initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError)" when saying smtp.start (CC BY‑SA 3.0/4.0)

#email #ruby #gmail #smtp






相關問題

Outlook 2007/2010 中的 Vspace (Vspace in Outlook 2007/2010)

JavaMail 無效的 MSGID (JavaMail invalid MSGID)

將電子郵件地址與地址標籤匹配的正則表達式 (regex that matches email addresses with address tags)

電子郵件地址中帶有 + 字符的 Java 郵件 (Java mail with + character in email address)

PHP mail() 中繼到郵件服務器 (PHP mail() relay to mail server)

在說 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)

電子郵件客戶端如何讀取內容類型標頭進行編碼? (How does an email client read the content-type headers for encoding?)

Return-Path 標頭的正確格式 (Correct format of an Return-Path header)

在應用購買中,我如何知道用戶是否已經購買了產品(消耗品)? (in app purchase, how do I know whether a user bought a product (consumable) already?)

將 Crystal Reports 轉換為 HTML 並作為正文發送到我的郵件中 (Crystal Reports into HTML and sending in my mail as body)

通過 smtp 從安裝為 azure 中的 IaaS 的服務器發送電子郵件 (sending emails via smtp from a server installed as IaaS in azure)

如何從 Excel 表格創建電子郵件? (How to create emails from Excel table?)







留言討論