postfix fails to send mail with "fatal: unknown service: smtp/tcp"
Solution 1:
On Debian, postfix doesn't read /etc/services
, but expects these files to exist in the queue_directory
(usually /var/spool/postfix). So it is actually trying to read /var/spool/postfix/etc/services
, which either doesn't exist or is corrupted.
Try recreating this file, or better yet just link it (if you aren't running postfix in a chroot).
sudo ln -snf /etc/services /var/spool/postfix/etc/services
If you are chrooting postfix, copy the file instead.
sudo cp -f /etc/services /var/spool/postfix/etc/services
Solution 2:
I encountered "fatal: unknown service: smtp/tcp" error because the SMTP daemon ran chrooted (which si default behavior on Debian for example) and the chroot environment wasn't properly set up. Check out official documentation.
To properly set up chroot environment you should use script for your platform provided in directory examples/chroot-setup
in the source code distribution. This will be usually taken care of by your package manager, but if you're compiling from source or running in Docker container this step will be mandatory for chrooted daemons to work.
You can always disable the chroot for postfix daemons (but beware of security implications) which will also solve this problem.