Ruby – Check Unread Messages From Gmail with ruby-gmail Gem

Filed under ruby
Tagged as , , , , , , , , , ,

Author: Kunto Aji
Site: http://www.railsmine.net
Summary: Ruby script to get all unread messages from Gmail. Visit http://github.com/dcparker/ruby-gmail for more info about ruby-gmail gem. This script is tested on Linux.
Usage: ruby ruby-gmail.rb

#!/usb/bin/ruby

#  _________      .__       .____   _______
# /   _____/ ____ |__|_____ |    |  \   _  \    ____
# \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
# /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
#/_______  /___|  /__|   __/|_______ \_____  /\___  /
#        \/     \/   |__|           \/     \//_____/
# http://www.railsmine.net

require 'rubygems'
require 'gmail'

username = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
gmail = Gmail.new(username, email)
unread_messages = gmail.inbox.emails(:unread)

puts "All unread messages"
for mail in unread_messages
        puts "----------------------------------"
        puts "From: #{mail.message.from}"
        puts "Subject: #{mail.message.subject}"
end

ruby,code,code,snippet

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*