通过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

你可能感兴趣的:(邮件,Ruby,Rails,pop3,ror)