Stop Bounces When Piping an Email to a Script

Recently I built a script to send sms messages from an email. This was to help me monitor my servers. However everytime I sent an email I got a bounce. I tried a lot of different things to stop the bounces and finally did. Here are some of the things you should try, and my ultimate solution.

Before you start you will need to use the piping/forwarding email tool in cpanel or whatever equivalent hosting control you have and set the right directory to send the scrip to. Here is a good tutorial on getting this part correct. Once you have that part working, then make sure all of the following are in place.

  • Start your script with this (if php) #!/usr/bin/php -q, it is a bash command calling php and telling it to use quiet mode.
  • Next make sure your script is not printing output to the page - so no print, echo or return commands which produce html or anything similar.
  • Next make sure there is no whitespace after the final ?> tag.
  • Do NOT use the dev null commands as they will disable your script entirely
  • Chmod (change permissions) on your file to a minimum of 755 or it won't work either

Finally if all of the above do not produce a solution for you, here is what you will need to do. Contact your server administrator (hopefully its you) to change settings in the exim.conf file. Locate the place in the file where it says

address_pipe:
driver = pipe
return_output

and change it to
address_pipe:
driver = pipe
return_fail_output

Next further down the page (just a few more lines) change this:
return_output
user = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"

to this:
return_fail_output
user = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"

Restart exim and you are all good.

Add new comment

Full HTML

  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.

Filtered HTML

  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.