Search code examples
rubyimapgmail-imap

Connection refused when using imap.rb to connect to imap.google.com


I'm trying to connect to a Gmail account (via ruby-gmail gem, gmail gem, gmail_xoauth gem over OAuth 2.0, but each method uses imap.rb) and getting:

C:/Ruby21-x64/lib/ruby/2.1.0/net/imap.rb:1045:in `initialize': No connection could be made because the target machine actively refused it. - connect(2) for "imap.gmail.com" port 993 (Errno::ECONNREFUSED)

On the Gmail account I have:

  1. Ensured it can be accessed through web login
  2. Ensured it's activated
  3. Enabled IMAP
  4. Allowed access for insecure apps

In the connection I have:

  1. Ensured it is made over SSL
  2. Ensured it uses correct login details and tokens where applicable
  3. Tried ports 993 and 465

What else could I try? How could I rule out the firewall being the issue, without having control over it?


Solution

  • .. (Errno::ECONNREFUSED)

    ... How could I rule out the firewall being the issue, without having control over it?

    It is probably a firewall. The error message says that the connection to the service got actively refused. Since it is working for me I doubt that it is google itself which is refusing the service so it must be a firewall in between.