后缀管道邮件到 ruby 脚本:'require GEM_NAME' 不加载宝石
postfix pipe mail to ruby script: 'require GEM_NAME' does not load gems
我正在尝试设置 postfix,它将收到的邮件通过管道传送到 ruby 脚本。我创建了一个用户 deploy
,它运行来自 postfix/master.cf
的脚本文件。当邮件收到 postfix 调用并执行 ruby 脚本但 require 'resque'
不会在该脚本中加载 resque gem。
这是来自 /var/log/mail.log
.
的错误日志
Jul 12 15:45:42 ubuntu-s-1vcpu-1gb-sfo2-01 postfix/pipe[3652]: 94ECE82A15: to=<deploy@mailet.in>, relay=myservice, delay=0.15, delays=0.05/0/0/0.1, dsn=5.3.0, status=bounced (Command died with status 1:
"/var/www/mail_getter/email_receiver.rb". Command output: /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in
`require':cannot load such file -- resque (LoadError) from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /var/www/mail_getter/email_receiver.rb:4:in `<main>' email receiver...... )
/etc/postfix/master.cf
:
myservice unix - n n - 2 pipe flags=XhqFBR user=deploy:deploy argv=/var/www/mail_getter/email_receiver.rb
这里是 /var/www/mail_getter/email_receiver.rb
:
#!/home/deploy/.rvm/rubies/ruby-2.5.1/bin/ruby
puts 'email receiver......'
require 'rubygems'
require 'resque'
require 'redis'
class EmailReceive
@queue = :incoming_email_queue
def initialize(content)
Resque.enqueue(EmailReceive, content)
end
end
EmailReceive.new($stdin.read)
注意:我也尝试使用 #!/usr/bin/env ruby
。
这里是 /etc/postfix/aliases
:
myservice: deploy
这里是 /etc/postfix/main.cf
:
myhostname = mail.mailet.in
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydomain = mailet.in
mydestination = $myhostname, $mydomain, ubuntu-s-1vcpu-1gb-sfo2-01, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
header_checks = regexp:/etc/postfix/header_checks
这里是 /etc/postfix/header_checks
:
/To:.*@mailet.in.*/ FILTER myservice:
这是 rvm list
输出:
=* ruby-2.5.1 [ x86_64 ]
ruby-2.7.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
注意:我也尝试从绝对路径要求 gems。
我在从 postfix 调用脚本时使用 wrappers
目录中的 ruby 解决了这个问题。
/etc/postfix/master.cf
的有效配置:
myservice unix - n n - 2 pipe
flags=XhqFBR user=deploy argv=/home/deploy/.rvm/wrappers/ruby-2.5.1/ruby /var/www/mail_getter/email_receiver.rb
我正在尝试设置 postfix,它将收到的邮件通过管道传送到 ruby 脚本。我创建了一个用户 deploy
,它运行来自 postfix/master.cf
的脚本文件。当邮件收到 postfix 调用并执行 ruby 脚本但 require 'resque'
不会在该脚本中加载 resque gem。
这是来自 /var/log/mail.log
.
Jul 12 15:45:42 ubuntu-s-1vcpu-1gb-sfo2-01 postfix/pipe[3652]: 94ECE82A15: to=<deploy@mailet.in>, relay=myservice, delay=0.15, delays=0.05/0/0/0.1, dsn=5.3.0, status=bounced (Command died with status 1:
"/var/www/mail_getter/email_receiver.rb". Command output: /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in
`require':cannot load such file -- resque (LoadError) from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /var/www/mail_getter/email_receiver.rb:4:in `<main>' email receiver...... )
/etc/postfix/master.cf
:
myservice unix - n n - 2 pipe flags=XhqFBR user=deploy:deploy argv=/var/www/mail_getter/email_receiver.rb
这里是 /var/www/mail_getter/email_receiver.rb
:
#!/home/deploy/.rvm/rubies/ruby-2.5.1/bin/ruby
puts 'email receiver......'
require 'rubygems'
require 'resque'
require 'redis'
class EmailReceive
@queue = :incoming_email_queue
def initialize(content)
Resque.enqueue(EmailReceive, content)
end
end
EmailReceive.new($stdin.read)
注意:我也尝试使用 #!/usr/bin/env ruby
。
这里是 /etc/postfix/aliases
:
myservice: deploy
这里是 /etc/postfix/main.cf
:
myhostname = mail.mailet.in
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydomain = mailet.in
mydestination = $myhostname, $mydomain, ubuntu-s-1vcpu-1gb-sfo2-01, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
header_checks = regexp:/etc/postfix/header_checks
这里是 /etc/postfix/header_checks
:
/To:.*@mailet.in.*/ FILTER myservice:
这是 rvm list
输出:
=* ruby-2.5.1 [ x86_64 ]
ruby-2.7.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
注意:我也尝试从绝对路径要求 gems。
我在从 postfix 调用脚本时使用 wrappers
目录中的 ruby 解决了这个问题。
/etc/postfix/master.cf
的有效配置:
myservice unix - n n - 2 pipe
flags=XhqFBR user=deploy argv=/home/deploy/.rvm/wrappers/ruby-2.5.1/ruby /var/www/mail_getter/email_receiver.rb