Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby1.9
- accounts = [{ :name => 'example',
- :server => 'mail.example.com',
- :username => 'user@example.com',
- :password => 'MySecretPassword',
- :method => 'PLAIN' }
- ]
- require 'net/imap'
- def check_mails(account)
- imap = Net::IMAP.new(account[:server])
- imap.authenticate(account[:method], account[:username], account[:password])
- imap.examine('INBOX')
- unread = 0
- imap.search(["UNSEEN"]).each do |message_id|
- unread += 1
- status = imap.status("INBOX", ["MESSAGES"])
- puts "#{account[:name].capitalize}: #{unread}/#{status["MESSAGES"].to_s}"
- imap.disconnect
- end
- accounts.each { |a| check_mails(a) }
Add Comment
Please, Sign In to add comment