Retrieve Gmail using Ruby

Posted by Kartik Rao on Stack Overflow See other posts from Stack Overflow or by Kartik Rao
Published on 2010-04-19T10:16:12Z Indexed on 2010/04/19 10:43 UTC
Read the original article Hit count: 538

Filed under:
|
|

I need to retrieve emails from my Gmail account using Ruby on Rails. I'm currently using this piece of code, but it gives me a timeout error everytime.

require 'net/pop'

pop = Net::POP3.new 'mail.isp.com'
pop.start '[email protected]', 'password'

if pop.mails.empty?
   puts "No mail."
else
   puts "You have #{pop.mails.length} new messages."
   puts "Downloading..."

   pop.mails.each_with_index do|m,i|
   File.open( "inbox/#{i}", 'w+' ) do|f|
   f.write m.pop
end

   m.delete
 end
end

This is the error I recieve

/usr/lib/ruby/1.8/timeout.rb:60:in `new': execution expired (Timeout::Error)
    from /usr/lib/ruby/1.8/net/protocol.rb:206:in `old_open'
    from /usr/lib/ruby/1.8/net/protocol.rb:206:in `old_open'
    from /usr/lib/ruby/1.8/net/pop.rb:438:in `do_start'
    from /usr/lib/ruby/1.8/net/pop.rb:432:in `start'
    from script/mail.rb:4

Any help will be appreciated!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails