2

I'm trying to setup exim4 on the server, so that it can receive mail for a couple sub domains, and I want to pipe that to a PHP script. I want all incoming mail to be processed through my custom script (PHP).

I posted some of my setting details below. I'm fairly new to setting this up, so I'm sorry if I'm totally off.

I've tried the following command, and it didn't seem to do anything. I couldn't see any new mail in /var/mail, and the PHP script didn't seem to be hit.

echo "This is a test." | mail -s Testing [email protected]

Here's the custom router, in exim4.conf:

cmd_router:
  driver = accept
  domains = +local_domains
  transport = cmd_transport
  no_verify

Here's the transport, in exim4.conf:

cmd_transport:
  debug_print = "T: using cmd_transport"
  driver = pipe
  command = /dir/to/php_mailer.php
  delivery_date_add
  envelope_to_add

Here's the update-exim4.conf.conf file:

dc_eximconfig_configtype='internet'
dc_other_hostnames='QAnetwork ; sub1.domain.net ; sub2.domain.net ; localhost'
dc_local_interfaces='127.0.0.1 ; 127.0.1.1 ; 123.123.123.123(server's external ip)'
dc_readhost='QAnetwork ; sub1.domain.net ; sub2.domain.net'
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='true'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

* Update *

I've been monitoring the exim4 mainlog after running the echo mail command, and getting the following:

2014-07-03 14:39:45 1X2lv7-0004mg-9Q <= root@ETC_MAILNAME U=root P=local S=488
2014-07-03 14:39:45 1X2lv7-0004mg-9Q ** [email protected]: Unrouteable address
2014-07-03 14:39:45 1X2lv7-0004mk-Br Error while reading message with no usable sender address (R=1X2lv7-0004mg-9Q): at least one malformed recipient address: root@ETC_MAILNAME - malformed address: _MAILNAME may not follow root@ETC
2014-07-03 14:39:45 1X2lv7-0004mg-9Q Process failed (1) when writing error message to root@ETC_MAILNAME (frozen)

I'm not really sure what to make of that error. I did some looking into the 'unrouteable address' error, but couldn't get it working.

Any ideas?

2
  • Edit your question and add a section which shows all log messages for an email that you tried to have delivered through this pipe transport. Include all messages for this example email, and any extra logging which you might be doing as this message is processed.
    – Todd Lyons
    Jul 3, 2014 at 13:10
  • Thanks for the suggestion Todd - I just added an update with the log message, after I send that email.
    – xil3
    Jul 3, 2014 at 18:45

1 Answer 1

1

You didn't give a lot of detail in your question, so I'll provide a list of general things to look at.

1) A common issue is that the php script is not readable and/or executable by the exim user. Test by setting the php script to mode 755 and resend.

2) Make sure the bang path in the script is correct. Typically this will be #!/usr/bin/php You should be able to run it from the commandline as if it was being called from exim:

cat temp.eml | /dir/to/php_mailer.php

3) Or if you are testing it by calling it as php /dir/to/php_mailer.php, then you need to set your transport to call the php binary directly as well. Use the full path to the php binary.

4) Few environment variables are set because the command not run under a shell (such as bash or sh). Instead the php script is directly executed by exim in the transport.

5) In general, the docs for the pipe transport are very good, so make sure you've read all the way through it and that you understand exactly what the options you are using do. You have a straightforward application of the pipe transport, and you are not doing anything super complicated with it. Pipe Transport

EDIT: After looking at your log message above, the problem does not seem to be your transport or your php script. The problem is the process sending the email to your Exim is saying the sender is root@ETC_MAILNAME instead of root at some valid domain name. You need to first fix whatever is sending the email to Exim. Alternatively, it could also be something wrong with your Exim configuration, because Exim may be expected to convert ETC_MAILNAME to the contents of the file /etc/mailname (standard operation for a Debian based Exim4 system).

3
  • Thanks for the suggestions Todd. I made sure 1,2 and 3 were fine. I added an update to my question, after digging in the mainlog for exim. Maybe that will shed some light - I'm still not sure how to fix it, though.
    – xil3
    Jul 3, 2014 at 18:44
  • Regarding your edit - the process sending the email is just echo "This is a test." | mail -s Testing [email protected], logged in as root. I'm not too sure how I'd change it to a valid domain name, since I'm sending it locally, for testing. Would you be able to point me to the right part of the config, which would convert ETC_MAILNAME?
    – xil3
    Jul 7, 2014 at 15:46
  • That value is set when you run 'update-exim4.conf', which will rebuild your /var/lib/exim4/config.autogenerated. It reads /etc/mailname to determine the hostname you want to send from by default.
    – Todd Lyons
    Jul 10, 2014 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .