Fetching email using Ruby on Rails
Asked Answered
C

2

6

I need to fetch email from my gmail account using RoR.

require 'net/pop'
Net::POP3.start('pop.gmail.com', 995, username, password) do |pop|  
    if pop.mails.empty?  
        puts 'No mail.'  
    else  
        #pop.each_mail do |mail|  
            #p mail.header  
            #p mail.pop
            puts "Mails present"
        #end  
     end  
 end  

I get a timeout error.

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

How do I fix that?

Corcovado answered 19/4, 2010 at 11:1 Comment(3)
Your account accept POP connection ?Citrus
Can you connect to the pop-host from the command-line? telnet pop.gmail.com pop or telnet pop.gmail.com 110. If that doesn't work, your problem is not related to RoR.Pellikka
telnet pop.gmail.com 995 Trying 74.125.127.109... Connected to pop.gmail.com. Escape character is '^]'. So,it does connect via telnetCorcovado
S
5

You need to use SSL

Sentiment answered 19/4, 2010 at 12:13 Comment(0)
S
17

Try this one:

require 'net/pop'
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)  
Net::POP3.start('pop.gmail.com', 995, username, password) do |pop|  
  if pop.mails.empty?  
    puts 'No mails.'  
  else  
    pop.each_mail do |mail|  
      p mail.header  
      p mail.pop  
    end  
  end  
end  
Slating answered 19/4, 2010 at 12:46 Comment(0)
S
5

You need to use SSL

Sentiment answered 19/4, 2010 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.