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

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.

If postfix fails to send emails, its better to check if PHP/WordPress can send email as well.

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.

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: /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.

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/

8 comments

      1. Got it working with sudo apt-get install bsd-mailx

        Just noting as the original command won’t work on a default install

  1. Hi,

    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.

    Thanks & Regards.
    MG

  2. hi Rahul ,
    you are doing nice work and very eassy to understand for dump like me in Linux 🙂
    i recently configure one Mail Gateway for our Hosted Exchange from some tutorial but it seems the PostFix and mailscanner not working . following is output of postconf -n which i learn from you 🙂 thanks
    in output online 12 it show error on localtransport .
    exit ();
    [root@MAIL-SVR05 ~]# postconf -n
    alias_database = hash:/etc/aliases
    alias_maps = hash:/etc/aliases
    command_directory = /usr/sbin
    config_directory = /etc/postfix
    daemon_directory = /usr/libexec/postfix
    data_directory = /var/lib/postfix
    debug_peer_level = 2
    header_checks = regexp:/etc/postfix/header_checks
    html_directory = no
    inet_interfaces = localhost
    inet_protocols = all
    local_transport = error:local mail delivery is disabled
    mail_owner = postfix
    mailq_path = /usr/bin/mailq.postfix
    manpage_directory = /usr/share/man
    message_size_limit = 10240000
    mydestination = local_recipient_maps =
    mydomain = MAIL-SVR05.amgexc.com
    mynetworks = 37.220.204.128/28, 255.255.255.240
    myorigin = MAIL-SVR05.xyz.com
    newaliases_path = /usr/bin/newaliases.postfix
    parent_domain_matches_subdomains = debug_peer_list, smtp_access_maps
    queue_directory = /var/spool/postfix
    readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
    relay_domains = amanatelecom.com,amanagroup.co.uk,cloud-coms.co.uk
    sample_directory = /usr/share/doc/postfix-2.6.6/samples
    sendmail_path = /usr/sbin/sendmail.postfix
    setgid_group = postdrop
    show_user_unknown_table_name = no
    smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service unix :postgrey/socket, permit
    transport_maps = hash:/etc/postfix/transport
    unknown_local_recipient_reject_code = 550
    virtual_alias_maps = hash:etc/postfix/virtual

    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

Comments are closed.