Sending Email from Chroot Environment

So you dont want to install the Sendmail daemon in every Chroot environment to be able to use the PHP mail() function? Of course not.. the simple solution is called mini_sendmail, it connects to localhost on port 25 to deliver the emails.

First of, download and compile the sourcecode:
# wget
# tar zxvf Mini_sendmail-1.3.6.tar.gz
# cd mini_sendmail-1.3.6
# make

Now you’ve got your new binary, lets try it out:
# echo -e "'Subject: test'\nTesting.." | ./mini_sendmail -f'' -v

If you are using the PHP7-FPM on Debian Stretch then edit the following file:

# vim /etc/php/7.0/fpm/pool.d/

php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -f''

Now you should be able to use the PHP mail() function from your Chroot

2018-07 Workaround for  "./mini_sendmail: can't determine username"
then you have to make the following changes to mini_sendmail.c

/* username = getlogin(); */
username = "";

and then recompile with:
# gcc mini_sendmail.c

By Nimpen J. Nordström

System Developer and Network Security Enthusiast

Leave a Reply

Your email address will not be published. Required fields are marked *