メール受信をトリガーにプログラムを実行したいと考えております。
###設定前の状態
CentOS 6.8
postfix + dovecotでメールサーバーを構築。
この時点で送受信を問題無く行なえます。
###行った事
受信時に実行されるプログラム
ruby
1# -*- encoding: utf-8 -*- 2#------------------------------------------------- 3# Ruby script to get a mail via alias of postfix. 4#------------------------------------------------- 5require 'mail' 6 7class GetMail 8 def initialize 9 dt = Time.now.strftime("%Y%m%d_%H%M%S%L") 10 @out_file = "/home/info/Document/txt.txt" 11 end 12 13 def execute 14 open(@out_file, "w+") do |f| 15 mail = Mail.new($stdin.read) 16 f.puts "From: #{mail.from.first}" 17 f.puts "To: #{mail.to.first}" 18 f.puts "Date: #{mail.date}" 19 f.puts "Subject: #{mail.subject}" 20 f.puts "Body:\n#{mail.body.decoded.encode("UTF-8", mail.charset)}" 21 end 22 rescue => e 23 $stderr.puts "[#{e.class}] #{e.message}" 24 e.backtrace.each{|trace| $stderr.puts "\t#{trace}"} 25 exit 1 26 end 27end 28 29exit unless $0 == __FILE__ 30GetMail.new.execute
postfixの設定
# info: :include:/tmp/TEST info: "| ruby /home/info/mail_trigger.rb"
上記を内容を「/etc/aliases」に追記した所、外部からのメールが受信できなくなりました。
外部からメールを送信すると「Undelivered Mail Returned to Sende」で帰ってきますが、クライアントではソフトではエラーは出ていません。
main.cfの設定
allow_mail_to_commands = alias,forward,include
postfixの設定とaliasesの設定では変更のたびにnewaliasesとrestartを行っています。
受信時のメールログ
Jan 24 19:02:50 v9193 postfix/smtpd[4313]: connect from mail-pf0-f173.google.com[209.85.192.173] Jan 24 19:02:50 v9193 postfix/smtpd[4313]: setting up TLS connection from mail-pf0-f173.google.com[209.85.192.173] Jan 24 19:02:50 v9193 postfix/smtpd[4313]: Anonymous TLS connection established from mail-pf0-f173.google.com[209.85.192.173]: TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits) Jan 24 19:02:51 v9193 postfix/smtpd[4313]: A12D2FC0BEC: client=mail-pf0-f173.google.com[209.85.192.173] Jan 24 19:02:51 v9193 postfix/cleanup[4318]: A12D2FC0BEC: message-id=<E42B1DF2-4293-4A0A-96D7-4142B8650CDB@gmail.com> Jan 24 19:02:51 v9193 postfix/qmgr[3638]: A12D2FC0BEC: from=<example@gmail.com>, size=2736, nrcpt=1 (queue active) Jan 24 19:02:51 v9193 postfix/local[4319]: A12D2FC0BEC: to=<info@server.com>, relay=local, delay=0.77, delays=0.76/0.01/0/0.01, dsn=5.3.0, status=bounced (Command died with status 127: " ruby /home/info/mail_trigger.rb". Command output: sh: ruby: command not found ) Jan 24 19:02:51 v9193 postfix/cleanup[4318]: D5598FC0BFD: message-id=<20170124100251.D5598FC0BFD@mail.server.com> Jan 24 19:02:51 v9193 postfix/bounce[4321]: A12D2FC0BEC: sender non-delivery notification: D5598FC0BFD Jan 24 19:02:51 v9193 postfix/qmgr[3638]: D5598FC0BFD: from=<>, size=4721, nrcpt=1 (queue active) Jan 24 19:02:51 v9193 postfix/qmgr[3638]: A12D2FC0BEC: removed Jan 24 19:02:51 v9193 postfix/smtpd[4313]: disconnect from mail-pf0-f173.google.com[209.85.192.173] Jan 24 19:02:52 v9193 postfix/smtp[4322]: certificate verification failed for gmail-smtp-in.l.google.com[74.125.204.26]:25: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority Jan 24 19:02:53 v9193 postfix/smtp[4322]: D5598FC0BFD: to=<example@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.204.26]:25, delay=1.7, delays=0/0.01/0.99/0.7, dsn=2.0.0, status=sent (250 2.0.0 OK 1485252173 s5si18562651plj.103 - gsmtp) Jan 24 19:02:53 v9193 postfix/qmgr[3638]: D5598FC0BFD: removed
備考
受信時に実行されるプログラムは実行権限をメールユーザーに与えています。
メールユーザーにログインしてプログラムを実行しても、権限関係のエラーなどは出ません。
##質問
このような状況でどこに問題があるのかわかりません。
メールログにはコマンド見つからないとなっていますが、該当ユーザーにスイッチしてプログラムを動かすと問題なく動きます。
どの辺りを見ればいいか教えて頂けないでしょうか?

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/24 12:46 編集
2017/01/24 21:01
2017/01/24 23:24
2017/01/25 04:54
2017/01/25 20:23