Bobcares

How to Flush Sendmail Queue on Ubuntu

PDF Header PDF Footer

Learn how to flush the Sendmail Queue on Ubuntu. Our Sendmail Support team is here to help you with your questions and concerns.

How to Flush Sendmail Queue on Ubuntu

Did you know that when Sendmail runs into a problem that prevents it from sending an email immediately, it stores the email in its mail queue?

The email will remain in this queue until the issue is fixed and Sendmail can successfully send it. Furthermore, Sendmail automatically tries to resend queued emails at regular intervals.

How to Flush Sendmail Queue on Ubuntu

However, in some cases, we may have to manually flush the queue if we need to send the emails urgently or if automatic resending isn’t working.

Our experts have put together these steps to help you out if an email gets stuck in the Sendmail queue.

  1. Check the Mail Queue
  2. Flush the Sendmail Queue
  3. Force Sendmail to Process the Mail Queue
  4. Clear the Sendmail Queue
  5. Print the Mail Queue
  6. Delete All Messages in the Mail Queue
  7. Use qtool.pl to Clear the Sendmail Queue
  8. Delete All Messages Queued for a Domain

Check the Mail Queue

Before flushing the queue, we have to check the current status of the mail queue to identify the emails waiting to be sent. So, follow these steps:

mailq Copy Code

Or

sendmail -bp Copy Code

These commands list the emails currently in the queue, along with details about each one.

Flush the Sendmail Queue

To flush the Sendmail queue, run this command:

sendmail -q Copy Code

This command tells Sendmail to process the mail queue immediately. Now, Sendmail will try to send all queued emails regardless of their scheduled retry time.

If we want to process the queue at defined intervals, we can use `-q` with a time parameter as seen here:

sendmail -q15m Copy Code

This will process the queue every 15 minutes. We can mention a time interval we prefer(`m` for minutes, `h` for hours, `d` for days).

Force Sendmail to Process the Mail Queue

In some cases, we have to force Sendmail to process the mail queue. This is necessary when emails are stuck in the queue because of issues like an unavailable recipient server. Run this command to force Sendmail to process the queue:

sendmail -q -v -f Copy Code

The `-v` option makes Sendmail operate in verbose mode. Hence, it offers more information about its tries to send each queued email. The `-f` option forces Sendmail to ignore any issues and try to send the emails.

Clear the Sendmail Queue

In extreme situations, we have to clear the mail queue entirely. This includes deleting all queued emails. This has to be done with caution, as it cannot be undone. Here is how to delete all queued messages:

sendmail -v -q -d Copy Code

Alternatively, we can delete individual messages as seen here:

sendmail -qI{Message-Id} Copy Code

Here, `{Message-Id}` is the ID of the message we want to delete.

Print the Mail Queue

We can use the `mailq` command to get a summary of the mail messages queued for future delivery:

mailqCopy Code

Or

sendmail -bpCopy Code

Delete All Messages in the Mail Queue

We can go to the `/var/spool/mqueue` directory and delete all files if we want to get rid of all messages in the queue:

cd /var/spool/mqueue/
ls
rm *
Copy Code

Use qtool.pl to Clear the Sendmail Queue

The Sendmail mail server does not provide any command to remove messages from the mail queue. To delete certain messages, we can use the `qtool.pl` script located in the Sendmail source code contrib directory:

  1. Use the `mailq` command to note down the Q-ID.
  2. Then, run `qtool.pl` as follows:
    ./qtool.pl -C /etc/mail/sendmail.cf -d /var/spool/mqueue/the_Q_ID
    Copy Code

    Here, `-C /etc/mail/sendmail.cf` is the Sendmail config file. And, `-d /var/spool/mqueue/p61J75u5037681` deletes the message specified by source (in this case, by Q-ID).

Delete All Messages Queued for a Domain

  1. First, set `QIDS` using the `mailq` command or manually:
    QIDS="qid1 qid2 qidN"Copy Code

    Or

    QIDS="$(mailq | grep -B1 'example-dot-com' | grep '^[a-z]'  | awk  '{print $1}' | sed  's/\*$//')"Copy Code
  2. Then, use this bash loop to delete all messages for `bobcares.com`:
    for q in $QIDS
    do
    /usr/local/bin/qtool.pl -C /etc/mail/sendmail.cf -d /var/spool/mqueue/$q
    done
    Copy Code

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to manage the Sendmail queue, ensuring that emails are sent promptly by flushing the queue in Ubuntu.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!