How to Flush the Mail Queue in Postfix


April 03, 2024
Written by
Rob Meyer
Contributor
Opinions expressed by Twilio contributors are their own
Reviewed by
Jesse Sumrak
Contributor
Opinions expressed by Twilio contributors are their own

How to Flush the Mail Queue in Postfix

Postfix is a popular open-source mail transfer agent (MTA) that routes and delivers email. Occasionally, as part of the administration of this service, users will view, flush, and purge Postfix mail queues. These actions facilitate the manipulation of email delivery, enabling message reprioritization and/or cancellation. Such actions often occur when the recipient's host defers or rejects the message.

What is Postfix queue?

When an email is sent via Postfix, it doesn't immediately get delivered to the recipient. Instead, it first enters the queue. There are several reasons for this staging process, including:

  • Processing: Emails may need to be processed or modified before sending, such as adding headers or performing virus scans.
  • Throttling: To avoid overwhelming the receiving server or violating policies, Postfix may throttle the number of messages sent within a certain time frame.
  • Delivery retries: If the first attempt to deliver an email fails, perhaps due to a temporary issue with the recipient's server, the message will stay in the queue. Postfix will then periodically retry sending the email until it is successfully delivered or the retry period expires.

The Postfix system typically manages multiple queues for different purposes:

  • Incoming Queue: Where new messages are initially placed.
  • Active Queue: Contains messages that are currently being delivered.
  • Deferred Queue: Holds messages that have been temporarily deferred because they couldn’t be delivered on the first attempt.
  • Hold Queue: Used for messages that an administrator has manually placed on hold.

Administrators can interact with these queues using various Postfix commands to view the status of emails, flush the queue to force processing, or purge emails to remove them from the queue entirely.

    What does a queued email mean?

    A queued email refers to an email message that has been placed in a queue or a waiting line for delivery. When an email is sent, it typically goes through several stages before reaching its intended recipient. One of these stages involves being placed in a queue for processing and delivery by the email server.

    Here's what happens when an email is queued:

    1. Processing: The email server processes the email, preparing it for delivery. This can involve several steps, including checking for spam, applying security filters, and possibly sorting it based on priority or other criteria set by the server's rules.

    2. Delivery Wait: The queued email waits its turn to be sent out. This waiting period can be influenced by several factors such as server load, network conditions, or prioritization rules that may delay certain emails.

    3. Delivery Attempt: The email server attempts to deliver the queued email to the recipient’s server. If successful, the email moves from the queue to the recipient's inbox. If not, it may be queued again for a later retry, especially if the issue is temporary (like a recipient server being down).

    The queuing system helps manage and optimize the flow of outgoing emails, ensuring that they are delivered in an orderly and efficient manner. It also provides a mechanism for handling errors and retries without losing any messages.

    How long does it take for a queued email to send?

    The process of queuing emails allows the server to manage and prioritize the delivery of messages based on various factors such as:

    • Server load
    • Network conditions
    • Recipient availability
    • Email deliverability

    When an email is queued, it means that it is awaiting its turn for processing and eventual delivery to the recipient's mailbox.

    Why is email queued?

    Sometimes, a message will send almost immediately. However, it can enter a queue for various reasons.

    For example, if the email server is experiencing high traffic or temporary connectivity issues, emails may accumulate in the queue until the server can process them. Additionally, certain email services or servers may have specific limitations or restrictions that could cause emails to be temporarily queued before being delivered.

    Once the queued email reaches the front of the queue and the necessary processing conditions are met, it will be delivered to the recipient's email address.

    How do you send queued emails?

    If an email gets queued, it means that it hasn't been sent yet due to certain circumstances. This isn't a problem (yet), so you don't need to take any immediate action. However, if you need to send an urgent message to your recipients or find your queue hasn't cleared in some time, here are some steps you can take to address the situation:

    1. Check your internet connection: Ensure that you have a stable internet connection. Sometimes, connectivity issues can prevent the email from being sent. If you're experiencing connectivity problems, try reconnecting or troubleshooting your internet connection.
    2. Verify the recipient's email address: Double-check the email address of the recipient to ensure it is correct. A small typo or error in the email address can cause the email to queue indefinitely or bounce back.
    3. Check the outgoing email server settings: Verify that your email client or application is correctly configured with the outgoing mail server settings. Ensure that the server address, port number, and authentication credentials (if required) are accurate.
    4. Wait for the queue to clear: If the email was queued due to temporary server issues or high email traffic, you might need to wait for the server to process the queue and send out the emails. In most cases, the server will automatically attempt to deliver the queued emails when it's back to normal operation.
    5. Contact your email service provider: If the email remains queued for an extended period or you suspect there may be an issue with your email service, reach out to your email service provider's support team for assistance. They can help troubleshoot the issue and provide guidance on how to send the queued email.

    View queued mail 

    In order to accomplish multiple queue operations, such as flushing or purging, we must first see what email is in the queue. To accomplish this, we'll use the postqueue -p command. 

    mailhost01:~ user01$ postqueue -p

    -Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------

    75E95197CF2E*     315 Wed Jul 15 16:27:07  sender@test.com

                                             recipient@test.com

     

    87717197CE88*     315 Wed Jul 15 16:26:39  sender@test.com

                                             recipient@test.com

    In the above example, each queue entry shows the queue file ID, message size, arrival time, sender, and the recipients that still need to be delivered.  The “*” or “!” characters at the end of the queue ID string represent the message’s queue status: active or hold. 

    Flush queued mail 

    To flush the mail queue, we'll use the postqueue -f command. This command will attempt to redeliver all queued mail. However, use the command sparingly, as multiple flushes will impact the overall performance of your mail server.  

    mailhost01:~ user01$ postqueue -f



    Purge queued mail 

    To purge the mail queue, we'll use the postsuper -d command. This command has 2 execution options: 

    Option 1

    To purge a single email from the queue, use the postsuper -d [message id] command. 

    mailhost01:~ user01$ postqueue -p

    -Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------

    75E95197CF2E*     315 Wed Jul 15 16:27:07  sender@test.com

                                             recipient@test.com

     

    87717197CE88*     315 Wed Jul 15 16:26:39  sender@test.com

                                             recipient@test.com

     

    mailhost01:~ user01$ sudo postsuper -d 75E95197CF2E

    postsuper: 75E95197CF2E: removed

    postsuper: Deleted: 1 message



    Option 2

    To purge all email from the queue, use the postsuper -d ALL command. 

    mailhost01:~ user01$ postqueue -p

    -Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------

    75E95197CF2E*     315 Wed Jul 15 16:27:07  sender@test.com

                                             recipient@test.com

     

    87717197CE88*     315 Wed Jul 15 16:26:39  sender@test.com

                                             recipient@test.com

     

    mailhost01:~ user01$ sudo postsuper -d ALL

    postsuper: Deleted: 2 message

     

    Increase your deliverability with Twilio SendGrid

    The need to manipulate mail queues is often the result of recipient hosts deferring or rejecting your messages. These deferrals or rejections will impact your overall email deliverability, which, in return, has a negative impact on your ability to communicate with your recipients.

    To read more about improving your email deliverability, review Twilio SendGrid’s annually published Email Deliverability Guide. And when you're ready to increase your deliverability, reach out to our Expert Services to get started for free. 


    Recommended For You



    Most Popular


    Send With Confidence

    Partner with the email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.