I would like all mail sent to a particular alias on a Linux machine to be processed by a perl script but sendmail is giving me a "Service unavailable" error and I don't understand what I'm missing.
I created my handle_email.pl script (right now, this just prints its parameters to /tmp/email.txt
) and added a symbolic link to it in /etc/smrsh
.
Then I added this to /etc/aliases
:
mailtest: |handle_email.pl
and ran newaliases
afterwards. Note that I've also tried mailtest: |/etc/smrsh/handle_email.pl
which gave the same results. I've also tried copying the actual script into /etc/smrsh
rather than a link, same results again.
When I send mail to the mailtest alias, the file in /tmp
never gets created, and I get this in /var/log/maillog:
Nov 1 14:43:59 localhost sendmail[24839]: qA1IhwHm024839: from=<xxx@xxx>, size=284, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=[10.7.160.180]
Nov 1 14:43:59 localhost smrsh: uid 8: attempt to use "handle_email.pl"
Nov 1 14:43:59 localhost sendmail[24850]: qA1IhwHm024839: to=|handle_email.pl, ctladdr=<mailtest@xxx> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=30570, dsn=5.0.0, stat=Service unavailable
Nov 1 14:43:59 localhost sendmail[24850]: qA1IhwHm024839: qA1IhxHm024850: DSN: Service unavailable
Nov 1 14:44:00 localhost sendmail[24850]: qA1IhxHm024850: to=<xxx@xxx>, delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=31594, relay=sy-int-mx.xxx. [<IP addr>], dsn=2.0.0, stat=Sent (qA1Ii4127508 Message accepted for delivery)
I get an email message describing the failure, which says:
The original message was received at Thu, 1 Nov 2012 14:58:16 -0400
from [<ip address>]
----- The following addresses had permanent fatal errors -----
|/etc/smrsh/handle_email.pl
(reason: Service unavailable)
(expanded from: <mailtest@xxx>)
----- Transcript of session follows -----
smrsh: "handle_email.pl" not available for sendmail programs
554 5.0.0 Service unavailable
Why will smrsh not execute my script?
Update: Answering questions in comments.
I've copied the script to /etc/smrsh
and removed the link. The file permissions are 0700 (also tried 0755) and the first line is #!/usr/local/bin/perl
which is correct. There is only one file in /etc/smrsh
. The ls -l output:
[main:g:64] xxx:/etc/smrsh# ls -l
total 4
-rwx------. 1 root root 281 Nov 1 16:35 handle_email.pl
Try changing the permission of /etc/smrsh/handle_email.pl to 755 and I think you'll have more success. You might want to restart sendmail just to be sure things are properly initialized and configured.
smrsh can be finicky. In your example the script is owned by root. Try changing ownership to mail.
You need to add handle_email.pl into /etc/smrsh but also every program that is executed from handle_email.pl. So if you use echo in order to write /tmp/email.txt you also need to do:
Edit: So in your case you need to link /usr/bin/perl