0

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=<201211011843.qA1IhwHm024839@localhost.localdomain>, 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
Graeme Perrow
  • 555
  • 1
  • 4
  • 16
  • What are the permissions on handle_email.pl? – mdpc Nov 01 '12 at 19:38
  • Does the handle_email.pl program first line have the appropriate and functional path to the PERL program? – mdpc Nov 01 '12 at 19:42
  • Also you might want to include the ls -l of /etc/smrsh directory. – mdpc Nov 01 '12 at 19:43
  • @mdpc Thanks for your responses - I've updated the question with the answers. – Graeme Perrow Nov 01 '12 at 20:43
  • 1
    First disable FEATURE(smrsh) from your sendmail.mc, rebuild sendmail.cf and restart sendmail. Then test whether your script works. If it does, or when it does, then come back and make it work with smrsh. But first check whether it works without it. – adamo Nov 03 '12 at 08:13
  • @adamo: Good idea. When I do that, it still fails but this time the bounce email says "permission denied". The script and all the directories are all 0755. `/usr/local/bin/perl` is a link to `/usr/bin/perl` which is 0755 as well. I've tried setting the owner of the script to mail.mail, no change. If I run the script as user mail (`su -m mail -c /etc/smrsh/handle_email.pl`), it runs properly. – Graeme Perrow Nov 03 '12 at 13:01
  • what about specifying the command in the alias as: "|/usr/bin/perl /path/to/script.pl" and then symlinking the perl binary in /etc/smrsh? This seemed to be helpful here: http://www.perlmonks.org/bare/?node_id=290975 – natxo asenjo Aug 09 '15 at 00:15
  • 1
    Dear downvoters: what's wrong with this question? – Graeme Perrow Mar 31 '16 at 22:38

3 Answers3

1

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.

mdpc
  • 11,856
  • 28
  • 53
  • 67
0

smrsh can be finicky. In your example the script is owned by root. Try changing ownership to mail.

Oleg Barshay
  • 133
  • 6
-1

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:

ln -s /bin/echo /etc/smrsh/echo

Edit: So in your case you need to link /usr/bin/perl

Jonas Bjork
  • 386
  • 1
  • 4