Rails mailer's receive and sendmail procmail "Service unavailable" problem
I have migrated all my Ruby on Rails system from Fedora Core 6 to RedHat 4.5 recently, and everything was fine, except for that the feature of blogging by email was broken (got a phone call today about that).
I use standard sendmail/procmail integration feature to receive mail to a designated address, and then pipe it into Rails Mailer's receive function.
So, it looks like that in my /etc/mail/virtusertable:
m@example.com examplemobile
this way all email which is coming to m@example.com address will be forwarded to system user called examplemobile.
In order to process the mail further and pipe it into my Rails script, I have the following setup in my /etc/aliases file :
examplemobile: "|/usr/local/bin/ruby /var/www/html/examplesite/current/script/runner -e production 'Mailman.receive STDIN.read'"
This setup worked perfectly on Fedora, but broke under RedHat. What's the problem? I was getting the following errors in my maillog:
Feb 13 11:45:33 appserv1 sendmail[32000]: m1D2jXJw032000: from=<xxxxxx@c.vodafone.ne.jp>, size=397, class=0, nrcpts=1, msgid=<20080213114719020972.1b6f@0016E68C4270>, proto=SMTP, daemon=MTA, relay=mmrts035p01c.softbank.ne.jp [123.108.236.87]
Feb 13 11:45:33 appserv1 smrsh: uid 8: attempt to use "ruby /var/www/html/examplesite/current/script/runner -e production 'Mailman.receive STDIN.read'" (stat failed)
Feb 13 11:45:33 appserv1 sendmail[32001]: m1D2jXJw032000: to="|/usr/local/bin/ruby /var/www/html/examplesite/current/script/runner -e production 'Mailman.receive STDIN.read'", ctladdr=<m@examplesite.com> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=30623, dsn=5.0.0, stat=Service unavailable
The problem turned out to be in sendmail setup under RedHat was more secure than the one I had in Fedora. Specifically, this has to do with smrsh (or Sendmail Restricted Shell) thingy. More info about it here. Basically, sendmail only allows piping to programs which (or aliases to them) are present in /etc/smrsh directory.
Since I only use ruby to pipe to, I have added a symbolic link to it inside the /etc/smrsh directory:
[mike@appserv1 smrsh]$ pwd
/etc/smrsh
[mike@appserv1 smrsh]$ ls -l
lrwxrwxrwx 1 root root 19 Feb 13 11:50 ruby -> /usr/local/bin/ruby
Everything works as it should now, and our mobile-blogging users are supposedly happy again :)