The Ruby Net::IMAP module has a bit of a warty interface, but it does work. It could do with a much nicer interface (perhaps a Net::IMAP::Simple equivalent?) and better docs. Here is a working example:

#!/usr/bin/env ruby

require 'rubygems'
require 'net/imap'
require_gem 'rmail'

imap ='host')
imap.login('username', 'password')
imap.examine('inbox')["SUBJECT", "Some text to look for", "SINCE", "11-Sep-2005"]).each do |message_id|
message =, ["BODY[]"])[0].attr['BODY[]'])
puts message.header.subject

Not too difficult once you work out what you need to be doing.

One thought on “Net::IMAP::Hairy

  1. More on Ruby and IMAP

    I’ve written here of a Ruby IMAP Script.
    The script is INCREDIBLY simple (but it had to do a simple thing nonethless):

    #!/usr/bin/env ruby
    begin_ =
    require ‘net/imap’
    if !ARGV[4]
    puts “USAGE: ruby imapcheck.rb [server] […

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.