habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Exim command remove emails queue specific Sender/Receiver – The “exiqgrep” usage

3 min read

Exim-command-to-remove-emails-from-mail-queue

We have already discussed the basic command usages of Exim mail server in one of the previous post. In this post I am explaining the command usages for finding or sorting emails in Exim mail queue for particular sender or receiver. We can sort it out in different ways, by using exim basic command and also by using the command “exiqgrep”.

To sort mail queue for a sender or receiver, you must have the idea about the field in Exim command output. Then you can simply sort it out with the help of “awk” and other Linux basic commands.

The default Exim command output field with details are explained below:

The “exim -bp” command output:

 4d  2.3K 1X0Baa-0006iR-Ml <>
          [email protected]

70h   999 1X0RmS-0002Ue-Fe <[email protected]m>
          [email protected]

In the above list, there are two mails in the mail queue. The queue field details are explained below:
1st field : Message’s age. (Eg: 4d : Four day)
2nd field : Size. (2.3k)
3rd field : Message ID (1X0Baa-0006iR-Ml)
4th field : sender. ([email protected])
5th field/second line : recipient address. ([email protected])

It’s really simple to find/sort email details for a particular user (Sender or Receiver) from the Exim mail queue. We have already discussed about the Exim mail server in different way. Here I am explaining different option to sort emails for a User.

See also  cPanel Exim Commands CheatSheet

Method I :

Basic method with “exim” command.
We can sort the emails by using the exim command, see the examples below:

I : List all emails from a particular sender:

 exim -bp|grep "username"

Where “username” is the sender name.
Example:

root@server [~]# exim -bp|grep olne5
43h  3.6K 1WFLFH-0006uA-Gk <[email protected]m>
43h  3.6K 1WFLOL-0000LX-97 <[email protected]m>
43h  1.9K 1WFLQG-0000hv-5M <[email protected]m>
43h  3.6K 1WFM7W-0001T5-7B <[email protected]m>
42h  6.0K 1WFMEn-0002yJ-A8 <[email protected]m>
42h  3.7K 1WFMGq-0003Sf-4T <[email protected]m>
42h  3.5K 1WFMyn-0002yN-Tt <[email protected]m>
------
------

Use “wc -l” to count total emails
Example:

root@server [~]# exim -bp|grep olne5|wc -l
191

How to remove ? Yes, that’s actually our discussion. You can remove all emails from that user using “awk” and “xargs “ options.
Syntax:

exim -bp|grep "username"| awk {'print $3'}| xargs exim -Mrm

Example:

exim -bp|grep olne5| awk {'print $3'}| xargs exim -Mrm

Sorry, I can’t illustrate the example here, because those emails are important for that user ? .

II : List all emails to a particular address:

exim -bp|grep "username"

Where “username” is the recipient address.
Note that, the recipient details is listed in the second line of “exim -bp” command’s output.

Example:

root@server [~]# exim -bp|grep ommdsdsd
44h  3.6K 1WFLFH-0006uA-Gk <[email protected]m>
          [email protected]
44h  3.6K 1WFLOL-0000LX-97 <[email protected]m>
          [email protected]
44h  1.9K 1WFLQG-0000hv-5M <[email protected]m>
          [email protected]
43h  3.6K 1WFM7W-0001T5-7B <[email protected]m>
          [email protected]
------
------
See also  How to check spamming Exim MTA Server

You can use the “awk” & “xargs” commands to remove it from the queue.

Method II :

By using the command “exiqgrep”
The command “exiqgrep” has some useful switches to manage emails which are in the Exim mail queue. Before deleting mails with exiqgrep you must have a little knowledge in “exiqgrep”.

The smart switches of “EXIQGREP” command:

1, -f : to search the exim mail queue for emails from a particular user.
Syntax:

exiqgrep -f user@domain

2, -r : to search the exim mail queue for emails to a particular address.
Syntax:

exiqgrep -r user@domain

3, -i : Prints the message ID
You can use it in different manner, some examples are;

Print the message-id of the entire queue:

exiqgrep -i

You can use it with -f and -r switches to get message ID of a particular sender or receiver.

exiqgrep -i [-r | -f] ...

4, -o : Prints messages older than a particular time.
Example:

exiqgrep -o 86400

Where time is specified in Seconds.

5, -y : Prints messages younger than a particular time.

6, -s : Prints messages with a particular size in bytes.
Example:

exiqgrep -s "^3..$"

“^3$” –> 3bytes
“^3.$” –> 3-30bytes
“^3..$” –> 3-300bytes
“^3…$” –> 3-3000bytes
And so on..

7, -z : list all frozen mails.

8, -x : List all unfrozen mails.

9, -c : Counts the matches with all of the above searches.
Example:

root@server [~]# exiqgrep -c -s "^3...$"
114 matches out of 584 messages

Alright, Hope you got an idea about the usages of “exiqgrep”, Now it is very simple to manage emails for a particular user with the help of “exiqgrep”.

See also  cPanel Exim Commands CheatSheet

How to remove all emails from a particular user using exiqgrep?

Do follow this command:

exiqgrep -i -f $user | xargs exim -Mrm

How to remove all emails to a particular user using exiqgrep?

Do follow this command:

exiqgrep -i -r $user | xargs exim -Mrm

Note – Original Source : https://www.crybit.com/remove-users-emails-form-mail-queue/

habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Leave a Reply

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

Never miss good article from us, get weekly updates in your inbox