Ubuntu – Sendmail smrsh alias script piping problem on Ubuntu/Debian

debianemailsendmailUbuntu

I have been banging my head against this problem for 2 weeks. What I am trying to do is pipe a sendmail alias (catchall for a virtusal domain) to a php script. However, I always get the following error (Cannot mail directly to programs):

Oct 7 14:35:49 fut-02 sm-mta[14057]: o97LZlmh014057: <5minutes@dev2.domain.com>… Cannot mail directly to programs
Oct 7 14:35:49 fut-02 sm-mta[14057]: o97LZlmh014057: from=, size=0, class=0, nrcpts=0, proto=ESMTP, daemon=MTA-v4, relay=mail-ww0-f46.google.com [74.125.82.46]

I have tried the following aliases in my virtusers file:

@domain.com "|php -q /home/myuser/myscript.php"
@domain.com "|/usr/bin/php5 -q /home/myuser/myscript.php"
@domain.com "|php5 /home/myuser/myscript.php"
@domain.com "|myscript.php"
@domain.com "|php5 myscript.php"

I have tried enabling smrsh in the sendmail.mc file 2 different ways:

FEATURE(`smrsh',`/usr/lib/sm.bin/smrsh')dnl
FEATURE(`smrsh')dnl

I then tried linking /usr/bin/php, /usr/bin/php5, (the actual binary), and the script itself to /etc/mail/smrsh/. I have also tried disabling smrsh altogether. Every test results in the same error. To verify smrsh is working I am able to successfully run:

/usr/lib/sm.bin/smrsh -c "/usr/bin/php5 -q /home/user/myscript.php"

A copy of my sendmail.mc is at the bottom of this post.

Am I missing something obvious? Is there possibly somewhere else in the Ubuntu/Debian sendmail configuration that can block mailing to scripts?

FWIW, I tried this setup on Ubuntu 10.10 RC and Debian 5. Same results on both with the exception that Debians default sendmail.mc comes formatted incorrectly (had FEATURES after the MAILER directives).

divert(0)dnl
#
#   Copyright (c) 1998-2005 Richard Nelson.  All Rights Reserved.
#
#  This file is used to configure Sendmail for use with Debian systems.
#
define(`_USE_ETC_MAIL_')dnl
include(`/usr/share/sendmail/cf/m4/cf.m4')dnl
VERSIONID(`$Id: sendmail.mc, v 8.14.3-9.2ubuntu1 2010-08-03 06:56:05 cowboy Exp $')
OSTYPE(`debian')dnl
DOMAIN(`debian-mta')dnl
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE
undefine(`confHOST_STATUS_DIRECTORY')dnl        #DAEMON_HOSTSTATS=
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE
dnl #
dnl # General defines
dnl #
dnl # SAFE_FILE_ENV: [undefined] If set, sendmail will do a chroot()
dnl #   into this directory before writing files.
dnl #   If *all* your user accounts are under /home then use that
dnl #   instead - it will prevent any writes outside of /home !
dnl #   define(`confSAFE_FILE_ENV',             `')dnl
dnl #
dnl # Daemon options - restrict to servicing LOCALHOST ONLY !!!
dnl # Remove `, Addr=' clauses to receive from any interface
dnl # If you want to support IPv6, switch the commented/uncommentd lines
dnl #
FEATURE(`no_default_msa')dnl
dnl DAEMON_OPTIONS(`Family=inet6, Name=MTA-v6, Port=smtp, Addr=::1')dnl
DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp')dnl
dnl DAEMON_OPTIONS(`Family=inet6, Name=MSP-v6, Port=submission, M=Ea, Addr=::1')dnl
DAEMON_OPTIONS(`Family=inet,  Name=MSP-v4, Port=submission, M=Ea')dnl
dnl #
dnl # Be somewhat anal in what we allow
dnl define(`confPRIVACY_FLAGS',dnl
dnl `needmailhelo,needexpnhelo,needvrfyhelo,restrictqrun,restrictexpand,nobodyreturn,authwarnings')dnl
dnl #
dnl # Define connection throttling and window length
define(`confCONNECTION_RATE_THROTTLE', `15')dnl
define(`confCONNECTION_RATE_WINDOW_SIZE',`10m')dnl
dnl #
dnl # Features
dnl #
dnl # use /etc/mail/local-host-names
FEATURE(`use_cw_file')dnl
dnl #
dnl # The access db is the basis for most of sendmail's checking
FEATURE(`access_db', , `skip')dnl
dnl #
dnl # The greet_pause feature stops some automail bots - but check the
dnl # provided access db for details on excluding localhosts...
FEATURE(`greet_pause', `1000')dnl 1 seconds
dnl #
dnl # Delay_checks allows sender<->recipient checking
FEATURE(`delay_checks', `friend', `n')dnl
dnl #
dnl # If we get too many bad recipients, slow things down...
define(`confBAD_RCPT_THROTTLE',`3')dnl
dnl #
dnl # Stop connections that overflow our concurrent and time connection rates
FEATURE(`conncontrol', `nodelay', `terminate')dnl
FEATURE(`ratecontrol', `nodelay', `terminate')dnl
dnl #
dnl # If you're on a dialup link, you should enable this - so sendmail
dnl # will not bring up the link (it will queue mail for later)
dnl define(`confCON_EXPENSIVE',`True')dnl
dnl #
dnl # Dialup/LAN connection overrides
dnl #
include(`/etc/mail/m4/dialup.m4')dnl
include(`/etc/mail/m4/provider.m4')dnl
dnl #
dnl # Default Mailer setup
FEATURE(`smrsh',`/usr/lib/sm.bin/smrsh')dnl
FEATURE(`virtusertable', `hash /etc/mail/virtusers')dnl
VIRTUSER_DOMAIN_FILE(`/etc/mail/virtdomains')dnl
MAILER_DEFINITIONS
MAILER(`local')dnl
MAILER(`smtp')dnl

Best Answer

You have to modify ruleset 0 (or ruleset 2) to work this out:

LOCAL_RULE_0
R$* < @ virtualdomain.com. > $*     $#prog $: $1 @ virtualdomain.com

The prog delivery agent is discussed at page 727 of the "bat book" (4th edition).

The above does not work with smrsh. It makes the assumption that $#prog is set to a program that decides what actions to take based on its argument.

You can even define your own delivery agent which will do exactly what you want, instead of trying to fit what is available to your case.

Related Topic