Exim, Postfix, and Dovecot commands cheat sheet

This cheat sheet brings together the commands for running a mail server on Linux, side by side: Exim and Postfix, which move email between servers, and Dovecot, which gives access to mailboxes over IMAP and POP3. It covers managing the mail queue, checking the configuration, reading the logs, checking mailboxes and quotas, and testing encrypted connections to the server. You can search for a command, filter by topic, and copy it with one click.

Mail queue: viewing and searching

  • exim -bp

    Exim: lists all the messages in the mail queue, with the message ID, age, size, sender, and recipients. Recipients the message has already been delivered to are marked with a D.

  • exim -bpc

    Exim: shows only the number of messages in the queue. Handy for a quick check of whether the queue is growing.

  • exim -bp | exiqsumm

    Exim: summarizes the queue by destination domain, so you can quickly see which domains have the most messages waiting.

  • exiqgrep -f user@example.com

    Exim: lists the queued messages sent from a specific address. The search is case-insensitive, and you can also search for part of an address, such as a domain.

  • exiqgrep -r example.com

    Exim: lists the queued messages where one of the recipients matches the text, for example all the messages to a specific domain.

  • exiqgrep -i -f user@example.com

    Exim: shows only the IDs of the matching messages, one per line. Used to pass the IDs to another command.

  • exiqgrep -c -z

    Exim: counts the frozen messages in the queue. Exim freezes a message when it can neither deliver it nor return it to the sender.

  • exiqgrep -o 86400

    Exim: lists messages that have been waiting in the queue longer than the given number of seconds, in this example more than a day.

  • postqueue -p

    Postfix: lists the mail queue, with the message ID, size, arrival time, sender, recipients, and the reason for the delay. The mailq command shows the same output.

  • postqueue -j

    Postfix: lists the queue in JSON format, one line per message, for processing in a script.

Mail queue: resending and deleting

  • exim -M MESSAGE-ID

    Exim: tries to deliver a specific message from the queue right away. Replace MESSAGE-ID with the ID shown by exim -bp. You can give several IDs separated by spaces.

  • exim -R example.com

    Exim: runs the queue only for messages where one of the recipients contains the text, for example after a problem on the destination domain's server has been fixed.

  • exim -qf

    Exim: tries to deliver all the messages in the queue that aren't frozen, even if their next retry time hasn't come yet.

  • exim -qff

    Caution: Exim tries to deliver all the messages in the queue, including frozen messages. On a large queue the command can load the server, so fix the reason the messages got stuck first.

  • exim -Mt MESSAGE-ID

    Exim: thaws a frozen message, so delivery attempts start again. The exim -Mf command does the opposite and freezes a message.

  • exim -Mrm MESSAGE-ID

    Caution: Exim deletes the message from the queue permanently, and the sender isn't notified. Check the message before you delete it.

  • exim -Mg MESSAGE-ID

    Exim: stops the delivery attempts for a message and sends the sender a bounce saying the message wasn't delivered. A bounce stuck in the queue is deleted.

  • exiqgrep -z -i | xargs exim -Mrm

    Caution: deletes all the frozen messages from the queue in one command, without confirmation. Run exiqgrep -z first and go over the list.

  • postqueue -f

    Postfix: tries to deliver all the messages in the queue right away. Running it often while messages keep failing slows down delivery of all the other mail.

  • postqueue -i QUEUE-ID

    Postfix: tries to deliver a single deferred message right away. Replace QUEUE-ID with the ID shown by postqueue -p.

  • postsuper -r QUEUE-ID

    Postfix: requeues a message for processing again, for example after a change to the routing settings. ALL instead of the ID requeues all the messages.

  • postsuper -h QUEUE-ID

    Postfix: puts a message on hold, so no delivery attempts are made. postsuper -H releases it from hold.

  • postsuper -d QUEUE-ID

    Caution: Postfix deletes the message from the queue permanently. Check the message with postcat before you delete it.

  • postsuper -d ALL deferred

    Caution: permanently deletes all the messages in the deferred queue. Without the queue name, -d ALL deletes all the messages from every queue, and they can't be recovered.

Content of a queued message

  • exim -Mvh MESSAGE-ID

    Exim: shows the headers of a queued message, such as the sender, the recipients, and the subject.

  • exim -Mvb MESSAGE-ID

    Exim: shows the body of a queued message.

  • exim -Mvl MESSAGE-ID

    Exim: shows the message's delivery log: which attempts were made and why they failed. The quickest way to understand why a message is stuck.

  • postcat -q QUEUE-ID

    Postfix: shows a queued message by its ID, together with the envelope data: the sender, the recipients, and the time it entered the queue.

  • postcat -hq QUEUE-ID

    Postfix: shows only the message headers. The -b option shows only the body, and the -e option shows only the envelope data.

Checking settings and routing

  • exim -bV

    Exim: shows the version, and also checks the configuration file and reports syntax errors. Values that are expanded at run time aren't checked.

  • exim -bP config_file

    Exim: shows the path of the configuration file in use.

  • exim -bP log_file_path

    Exim: shows a single setting by name, in this example the location of the logs. Without a setting name, exim -bP shows all the main settings.

  • postconf -n

    Postfix: shows only the settings set explicitly in the main.cf file. The usual way to share your settings when you ask for help.

  • postconf -d message_size_limit

    Postfix: shows the default value of a setting. Without -d it shows the current value, and postconf without a setting name shows all the settings.

  • sudo postconf -e 'message_size_limit = 52428800'

    Postfix: changes a setting in the main.cf file without opening the file for editing. Run postfix reload for the change to take effect.

  • postconf -M

    Postfix: shows the services defined in the master.cf file, such as submission on port 587.

  • sudo postfix check

    Postfix: checks the permissions and ownership of the Postfix files and directories, and warns about problems.

  • doveconf -n

    Dovecot: shows only the settings changed from the defaults. This is also what doveconf does when you run it without options.

  • doveconf ssl_min_protocol

    Dovecot: shows a single setting by name. The -d option shows its default value.

  • exim -bt user@example.com

    Exim: checks where a message to an address would be delivered: a local mailbox, a redirect to another address, or a remote server. No message is actually sent.

  • exim -bh 192.0.2.10

    Exim: simulates an SMTP session as if it came from the given IP address, and shows which server checks ran at each stage. Type SMTP commands such as EHLO, MAIL FROM, and RCPT TO. The message isn't delivered and isn't written to the logs.

Logs

  • exigrep user@example.com /var/spool/exim/log/mainlog

    Exim: shows all the log lines of every message related to the address, not only the line where the address appears. The log location varies between installations, and you can find it with exim -bP log_file_path.

  • eximstats /var/spool/exim/log/mainlog

    Exim: generates a statistics report from the log on the mail received and delivered.

  • exiwhat

    Exim: shows what each Exim process is doing right now, such as which message it is delivering. Meant for occasional use, and usually requires root privileges.

  • /var/log/maillog

    The mail log on Red Hat family distributions: sending, receiving, and mailbox logins.

  • /var/log/mail.log

    The mail log on Ubuntu, and on Debian when rsyslog is installed.

  • sudo grep QUEUE-ID /var/log/maillog

    Postfix: shows all the log lines related to one message, by its queue ID. On Ubuntu and Debian, search /var/log/mail.log.

  • journalctl -u 'postfix*' --since today

    Postfix: shows the mail log from the system journal, since the start of the day. The postfix* pattern also catches service units with extended names, such as postfix@-.

  • journalctl -u dovecot -f

    Dovecot: shows the Dovecot log and adds new lines in real time. Suited to following a failed login attempt.

  • doveadm log errors

    Dovecot: shows the latest errors and warnings, up to 1,000, since the service last started.

  • doveadm log find

    Dovecot: shows the location of the Dovecot log files.

Dovecot: users, mailboxes, and quotas

  • doveadm who

    Dovecot: shows who is connected to mailboxes right now, from which IP addresses, and over which protocol. The -1 option shows one line per connection.

  • doveadm user user@example.com

    Dovecot: checks that the user exists and shows the user's details, such as the home directory and the mailbox location.

  • doveadm auth test user@example.com

    Dovecot: tests a user's login. The command asks for the password, and it's better not to type it on the command line, because it is saved in the shell history.

  • doveadm auth cache flush

    Dovecot: clears the authentication cache, for example after a password change that hasn't taken effect yet. You can give a specific user at the end of the command.

  • doveadm quota get -u user@example.com

    Dovecot: shows the mailbox's quota usage and its limit. The size is shown in kilobytes, and the command works when the quota plugin is enabled.

  • doveadm quota recalc -u user@example.com

    Dovecot: recalculates the quota usage, for example when the size shown doesn't match the actual size of the mailbox.

  • doveadm mailbox list -u user@example.com

    Dovecot: lists all the folders in the user's mailbox.

  • doveadm mailbox status -u user@example.com 'messages vsize' INBOX

    Dovecot: shows the number of messages and the size of a folder. The value all shows all the fields.

  • doveadm force-resync -u user@example.com INBOX

    Dovecot: repairs a folder with a corrupted index, when the automatic repair wasn't enough.

  • doveadm kick user@example.com

    Dovecot: disconnects all of the user's connections, for example after a password change.

Restarting the services

  • sudo systemctl restart exim

    Exim: restarts the service after a configuration change. On distributions where the service is called exim4, use that name.

  • sudo postfix reload

    Postfix: reloads the settings without stopping the service. Running processes finish their work and start again with the new settings.

  • sudo systemctl reload postfix

    Postfix: reloads the settings through systemd, if you manage all your services the same way.

  • sudo postfix status

    Postfix: checks whether the service is running.

  • sudo doveadm reload

    Dovecot: reloads the settings. Run doveconf -n first, which reports errors in the configuration file.

  • sudo systemctl restart dovecot

    Dovecot: restarts the service. For a configuration change, doveadm reload is usually enough.

  • systemctl status exim postfix dovecot

    Shows the status of the services. A server usually runs only one of Exim and Postfix, and a service that isn't installed is shown as not found.

Testing encrypted connections with openssl

  • openssl s_client -connect mail.example.com:465 -crlf

    Tests an encrypted SMTP connection on port 465 (SSL/TLS). After a successful connection, the server shows a greeting line that starts with 220, and you can type EHLO example.com and QUIT.

  • openssl s_client -connect mail.example.com:587 -starttls smtp -crlf

    Tests an SMTP connection on port 587 with STARTTLS, the port email clients use for sending.

  • openssl s_client -connect mail.example.com:25 -starttls smtp -crlf

    Checks that the server accepts mail from other servers on port 25 and supports encryption. Run it from outside the server, to test the connection the way other servers see it.

  • openssl s_client -connect mail.example.com:993 -crlf

    Tests an encrypted IMAP connection on port 993. After a successful connection, the server shows a greeting line with the word OK.

  • openssl s_client -connect mail.example.com:143 -starttls imap -crlf

    Tests an IMAP connection on port 143 with STARTTLS.

  • openssl s_client -connect mail.example.com:995 -crlf

    Tests an encrypted POP3 connection on port 995.

  • openssl s_client -connect mail.example.com:993 -brief < /dev/null

    Shows a summary of the connection: the TLS version, the cipher, and the certificate, and exits right away. Suited to a quick check of the certificate on the mail server.

Exim, Postfix, and Dovecot: who does what

  • Exim and Postfix: mail transfer agents (MTAs). They accept messages from other servers on port 25, accept outgoing messages from email clients on ports 465 and 587, and deliver them to the destination server. A server usually runs only one of them, so some of the commands on this page will fit your server and some won't.
  • Dovecot: gives access to mailboxes over IMAP and POP3, and on many servers also verifies the username and password for sending over SMTP.

To see which service listens on the mail ports, run sudo ss -ltnp and look for ports 25, 587, and 993.

Before you delete messages from the queue

A queue that grows fast is usually a sign of a problem, such as a hacked mailbox sending spam or a destination server rejecting the messages. Before you delete anything, check how many messages came from the same sender, read the delivery log of one of them, and fix the cause, for example by changing the password and blocking the mailbox temporarily. If the cause isn't fixed, the queue fills up again. The error codes that appear in the logs are explained on the SMTP error codes page.

The message ID, the addresses, and the server name on this page are examples, so replace them with your real values. On some distributions the Exim command is called exim4. The ports and encryption to set in email clients are listed on the Email client settings page.

Did you know?

A Linux VPS gives you full root access and a dedicated IP address, so you can run your own mail server with every command on this page. On request, we set up a PTR record for the server's address, which sending email usually requires. If your business prefers mailboxes on its own domain without managing a server, our business email service is available.

Linux VPS plans

Mail server commands FAQ

What is the difference between Exim, Postfix, and Dovecot?

Exim and Postfix are mail transfer agents: they accept messages, send them on to the destination servers, and keep a queue of messages that haven't been delivered yet. A server usually runs only one of them. Dovecot is the service that email clients on computers and phones connect to in order to read messages, over IMAP and POP3. A typical mail server runs Dovecot together with one of the other two.

How do I check how many messages are waiting in the mail queue?

On Exim, run exim -bpc, which shows the number of messages, or exim -bp | exiqsumm for a summary by destination domain. On Postfix, run postqueue -p, and the last line of the output sums up the number of messages and their total size. A small queue that empties on its own is normal, because messages wait there until the recipient's server is available.

How do I resend messages stuck in the mail queue?

First, find out why the message is stuck: on Exim with exim -Mvl and the message ID, and on Postfix in the reason column of the postqueue -p output. Once the cause is fixed, on Exim run exim -M with the message ID, or exim -qf for the whole queue, and on Postfix run postqueue -i with the ID, or postqueue -f for the whole queue.

How do I check that my mail server accepts encrypted connections?

Connect with openssl s_client to each of the ports: 465 and 993 for connections encrypted from the start, and 587 with the -starttls smtp option. A successful connection shows the certificate details and the server's greeting line. The output also shows the certificate's expiry date and the name on it, so make sure the name matches the server name set in your email clients.

Do I need to restart the service after changing the settings?

Yes. On Postfix, reloading the settings with postfix reload is enough and doesn't stop the service. On Dovecot, run doveadm reload, and on Exim, restart the service. Check the configuration file first, on Exim with exim -bV and on Dovecot with doveconf -n, so a syntax error doesn't stop the service.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement