Fetching email using Ruby on Rails

不问归期 提交于 2019-12-31 17:58:03

问题


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?


回答1:


You need to use SSL




回答2:


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  


来源:https://stackoverflow.com/questions/2666798/fetching-email-using-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!