通过POP3读取邮件

阅读更多

  require 'net/pop'

  pop = Net::POP3.new('pop3.example.com')
  pop.start('YourAccount', 'YourPassword')            
  if pop.mails.empty?
    puts 'No mail.'
  else
    i = 0
    pop.each_mail do |m|   
      File.open("inbox/#{i}", 'w') do |f|
        f.write m.pop
      end
      m.delete
      i += 1
    end
    puts "#{pop.mails.size} mails popped."
  end
  pop.finish 

 

更多例子请参考http://www.ensta-paristech.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/pop/rdoc/classes/Net/POP3.html

你可能感兴趣的:(POP3,邮件,ruby,rails,ROR)