Note: Please check common mistakes with mail server first.
You will need to debug postfix, when you are facing email related issues like emails are not sent, emails are delivered but with a long delay, mail bounces, etc.
In this article, we will first see how we can check if postfix itself can send emails. Then we will see postfix configuration/re-configuration and some related parameter. It will be followed by checking postfix mail logs for errors and finally inspecting mail queues to diagnose different postfix related problems.
Check if postfix can send emails
If your WordPress or PHP or any other application is not able to send emails, first thing you should check if postfix can send emails itself.
echo "Test mail from postfix" | mail -s "Test Postfix" email@example.com
Please replace firstname.lastname@example.org. Its better to run a test with your free email id with gmail, yahoo, etc first. If you can receive test mail sent above then that means postfix is able to send emails.
If postfix fails to send emails, its better to check if PHP/WordPress can send email as well.
You can run command
postconf -n and it will show postfix config in action! This is very convenient as reading config files with lots of comments can get tiring sometimes. Though you can skip commented part using this also,
postconf -n is quite handy and useful.
It’s sample output consist lines like below:
mydestination = $myorigin, localhost.rtcamp.com, localhost myhostname = $myorigin mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 myorigin = /etc/mailname
I have skipped other lines because most issues are related to above lines (in my experience).
If you see anything wrong, you can fix it up by editing
/etc/postfix/main.cf file. If you make any changes to postfix config, don’t forget to reload it by running command:
On Ubuntu/Debian, you can run command
dpkg-reconfigure postfix .
It will start an interactive wizard which will guide you through different configurations.
One important config value is hostname of your system. To check it, run
hostname command. It should show a domain you like to use to send mails from. If you want to change it, you better change /etc/hostname file. It just contains one line.
Its also recommended to add a line like below in your
127.0.0.1 host1.example.com host1
For better email delivery, you must create “A record” on DNS for example.com pointing to public IP of your machine hosting
Check postfix mail logs
When you run into postfix or email issues, first thing, you should check is postfix mail logs which are present in
It contains postfix’s general logs. Keeping
tail -f /var/log/mail.log running in a separate terminal window will be helpful.
If you can see a file
/var/log/mail.err then its better to check it first.
mail.err is only for “error” logging.
There are many kind of error messages possible. Not all are added by postfix! Some other applications like dovecot, cyrus, etc also make use of these log files. Its better to Google first as solutions for most of common errors are already present out there.
Read this if you want to get more detailed postfix logs.
Checking postfix queue
This is covered in details here – https://rtcamp.com/tutorials/mail/postfix-queue/