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?
Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.
Then the preview will be available in http://localhost:3000/rails/mailers/user_mailer/welcome_email. If you change something in app/views/user_mailer/welcome_email. html. erb or the mailer itself, it'll automatically reload and render it so you can visually see the new style instantly.
1 What is Action Mailbox? Action Mailbox routes incoming emails to controller-like mailboxes for processing in Rails. It ships with ingresses for Mailgun, Mandrill, Postmark, and SendGrid. You can also handle inbound mails directly via the built-in Exim, Postfix, and Qmail ingresses.
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
You need to use SSL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With