开发者

simple ruby script that tests out mail lib not working, please help

开发者 https://www.devze.com 2023-01-18 16:37 出处:网络
Using irb the mail library worked fine, now I am creating my first ruby script. I am getting the error:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消