Check Unread Gmail Messages with Ruby

How to check the number of unread Gmail messages in my mailbox with a short Ruby script?

+3
source share
2 answers

Use ruby-gmail

gem install ruby-gmail mime

irb(main):001:0> require 'gmail'
=> true
irb(main):002:0> gmail = Gmail.new("email@gmail.com", "password")
=> #<Gmail:0x1ea65d8 (email@gmail.com) disconnected>
irb(main):004:0> gmail.inbox.count(:unread)
=> 42
+4
source

The Nash solution worked for me as soon as I added require 'rubygems'as a first step.

Before that I got the following error when using require 'gmail'.

LoadError: no such file to load -- gmail
+1
source

All Articles