Debugging Postfix Config, Mail Logs & more

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.

Please replace admin@something.com. 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.

Postfix configuration

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.

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: /etc/init.d/postfix reload

Reconfigure postfix

On Ubuntu/Debian, you can run command dpkg-reconfigure postfix .

It will start an interactive wizard which will guide you through different configurations.

Hostname

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 /etc/host file

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 host1.example.com.

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 /var/log/mail.log file.

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.

I am using postfix on centos 6.4. Now there are lotsof mails in mailq. When i checked email, i show there are lots of email from —-@mail.ru. I don’t know about this email domain. Can you please suggest me that how to remove all mail from mailq, which is associated with ……..@mail.ru.

i dont understand how to resolve this error . your help will surly save my life 🙂 thanks in advance
Note : i was not able to send mail from Postfix in Centos was relpyng no mail command found also try to install apt-get install mailutils . 🙁 no luck