mailq Command: Tutorial & Examples

Display the mail queue

The mailq command is a handy tool used within a Linux system to display the mail queue. The mail queue is the place where emails hang out while they're waiting to be delivered. If you're running a mail server, it can be quite beneficial to see what's in your mail queue. The mailq command allows you to do just that.

How It Works

The mailq command interfaces with your mail transfer agent (MTA), such as Sendmail or Postfix, to retrieve and display the mail queue. It's essentially a shortcut for sendmail -bp, which is the command that actually interacts with the MTA.

Here's an example of how to use it:


Running the command without any options will display the entire mail queue.

What It Is Used For

The primary use for the mailq command is to monitor and manage the mail queue. For instance, if you notice that your emails are not being sent or received, you can use the mailq command to check if they're stuck in the queue.

Why It Is Important

Monitoring your mail queue can help you catch and troubleshoot issues with your mail server before they become larger problems. For example, a sudden increase in the size of the mail queue could indicate a network issue, a misconfigured MTA, or even a spam attack.

How to Use It and Common Command Line Parameters

The mailq command is straightforward to use. Simply typing mailq and pressing enter will display the mail queue. However, there are also a few additional parameters that you can use to customize the output:

  • -v: Verbose mode. This will display additional information about each message in the queue.
  • -Ac: Show the active queue instead of the deferred mail queue.
  • -Am: Show the deferred mail queue instead of the active queue.

For example:

mailq -v

This will show the mail queue with verbose output.

Potential Problems and Pitfalls

There are a few potential issues you might encounter when using the mailq command:

  • Permission issues: The mailq command needs to be run as a user with adequate permissions, typically root or the mail user. If you run it as a regular user, you may see an error message.
  • MTA compatibility: The mailq command works with most MTAs, but not all. If your MTA is not compatible, you may have to use a different command to view the mail queue.


Here are a few examples of how to use the mailq command:

  • To view the mail queue:

  • To view the mail queue with verbose output:

    mailq -v
  • To view the active mail queue:

    mailq -Ac
  • To view the deferred mail queue:

    mailq -Am 

In each case, the command will print the contents of the mail queue to the screen. The output includes the ID of each message, the size of the message, the date and time the message was received, and the sender and recipients of the message.

The text above is licensed under CC BY-SA 4.0 CC BY SA