2

With my Ruby script:

imap = Net::IMAP.new('imap.gmail.com')
imap.login("some_email@host.com", password)

I get the following exception:

A connection attempt failed because
the connected party did not properly
respond after a period of time, or
established connection failed because
connected hos has failed to respond. -
connect(2)

What's wrong?

lorem monkey
  • 3,942
  • 3
  • 35
  • 49
Oksana
  • 13,442
  • 10
  • 53
  • 89

1 Answers1

6

You need to connect using SSL on port 993.

Therefore your code should be this:

imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login("user@host.com", "password")
Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • I get exception: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificat e verify failed – Oksana Oct 05 '10 at 11:51
  • 1
    There is probably a mismatch in the certificate (e.g. cn on the cert is not the same as imap.gmail.com) or perhaps the certificate signer is not in your store. If you want to ignore SSL issues, try this: `imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false)`. Doc link: http://ruby-doc.org/stdlib/libdoc/net/imap/rdoc/classes/Net/IMAP.html#M000754 – Brian Oct 05 '10 at 15:18
  • 2
    @Oksana - by the way, it's not a good idea to ignore the SSL errors. You really should try & find out why you are getting them & fix the core problem. But, at least you know know your code works & there is a problem elsewhere. – Brian Oct 06 '10 at 22:26