`require'出错:无法加载此类文件 - 邮件

时间:2014-04-07 03:13:49

标签: ruby rvm

我们正在运行Postfix邮件传输程序。我们已经指定当收到传入的电子邮件时,将其发送到Ruby脚本。

后缀中的命令是:

flags=Xhq user=vmail argv=/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby /home/usera/rails/project/lib/email_receiver_script

当我们收到电子邮件时,mail.log中有一个错误:

Apr  6 20:02:48 railsdev postfix/pipe[25961]: B447A282D01: to=<rr@myapp.com>, relay=send_to_ruby_filter, delay=0.06, delays=0.01/0/0/0.05, dsn=5.3.0, status=bounced (Command died with status 1: "/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby". Command output: /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mail (LoadError)  from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'  from /home/usera/rails/project/lib/email_receiver_script:4:in `<main>' )

但是命令使用命令行运行得很好。如果我使用email.txt并将其传递给相同的命令,邮件就会正确地传递给脚本。像这样:

cat email.txt | /usr/local/rvm/rubies/ruby-2.1.1/bin/ruby /home/usera /rails/project/lib/email_receiver_script

我们脚​​本的前几行是:

#!/usr/bin/env ruby 
require 'rubygems'
require 'mail'
require 'redis'
require 'resque' 

RVM用作root用户全局安装Ruby。

好像是后缀用户&#39; vmail&#39;找不到安装的Rubygems。我们如何才能使它正确执行脚本?

2 个答案:

答案 0 :(得分:1)

在走到互联网的尽头然后再回来我找到了解决方案。使用RVM wrappers。制作包装器后,您需要使用rvm 2.1.1@global do bundle install将宝石捆绑到包装器中。之后我将postfix命令更改为:

flags=Xhq user=vmail argv=/usr/local/rvm/wrappers/ruby-2.1.1@my_app/ruby /home/usera/rails/project/lib/email_receiver_script

&#34; Getting Postfix to Send Incoming Mail to Rails&#34;。

还有其他信息

答案 1 :(得分:0)

因为你传递的红宝石路径如下:

cat email.txt | **/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby**
/home/usera /rails/project/lib/email_receiver_script

尝试不在脚本中使用shebang?我不确定“/ usr / bin / env ruby​​”是否返回正确的env范围。