views:

30

answers:

3

Using irb the mail library worked fine, now I am creating my first ruby script.

I am getting the error:

testmail.rb:3:in `require': no such file to load -- mail (LoadError)
    from testmail.rb:3

Below is the file testmail.rb:

#!/usr/bin/env ruby

require 'mail'



if __FILE__ == $0

  Mail.defaults do
    retriever_method :pop3, { :address             => "mail.blah.com",
                             :port                => 995,
                             :user_name           => '[email protected]',
                             :password            => 'asdfasdf',
                             :enable_ssl          => false }
    end

  emails = Mail.all

end
A: 

In irb execute puts$: and at the command line execute ruby -e "puts $:" You should see which gem path you are missing.

ennuikiller
in irb it just outputs '$:'
Blankman
sorry it should be puts $: without quotes
ennuikiller
both outputs look exactly the same...
Blankman
A: 

How did you install the mail library? Which version of Ruby are you using? Which package did you use to install Ruby?

If you installed mail via RubyGems, for example, and you are using Ruby 1.8, then you have to make sure that the RubyGems library is loaded before you load any Gems. Or more precisely, your administrator should have your environment set up in such a way that RubyGems gets loaded for you.

Jörg W Mittag
I have ruby 1.8.7, I installed it using: sudo gem install mail
Blankman
+1  A: 

You need to require rubygems before requiring any gem:

require "rubygems"
require "mail"

should work.

J. Pablo Fernández