simple ruby script that tests out mail lib not working, please help
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 =&开发者_开发技巧gt; 995,
:user_name => 'test@blah.com',
:password => 'asdfasdf',
:enable_ssl => false }
end
emails = Mail.all
end
You need to require rubygems before requiring any gem:
require "rubygems"
require "mail"
should work.
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.
In irb execute puts$:
and at the command line execute ruby -e "puts $:"
You should see which gem path you are missing.
精彩评论