How remove a lot of mail from mailq with few cli comands.

Hello,

We have a lot of mail with errors like:

D7AF9121256 34341 Tue Nov 21 11:19:27 MAILER-DAEMON ……….

We want to remove them.

First commands:

mailq | grep MAILER-DAEMON | awk ‘{ print $1 }’ > /root/mailq-201711.txt

Here we catch the ID like D7AF9121256 each mail and save in file /root/mailq-201711.txt.

cat /root/mailq-201711.txt

F0DFF124FDB*
D79941257D6*
75668125191*
5879A1256F4*
4A9DB124CA3*
489E6124A01*
C7DC9124A8A*
3EE891252EC*
7E956125735*
69B0E124DAA*
58F9E12535D*
8DBF71255A0*
8D633125035*
08A411254DE*
549C9124902*
8144B12537B*
D927512497A*
6606C125774*
E09BA125439*
538091259BD*
1F749125973*
8A9CB1255DC*
1D949124DD7*
13B1812546E*

Now we have to remove caracacter * from each ID because we get error to next commands.
Open file /root/mailq-201711.txt with vim and execute commands :1,$ s/*/<space>/g   where 1 it’s first line and $ last line.   Save file and exit ( :wq )

And now delete mails form mailq with:

while read i; do postsuper -d $i; done </root/mailq-201711.txt

After read each line I delete ID with postsuper -d $i and read next line.   Enjoy!

How to activate dovecot plugin log delete mail

Hello,

Today I need to see in log file who delete mails.

First we activate plugins mail_log in dovecot
Edit: vim /etc/dovecot/conf.d/20-imap.conf

# Host allowed in URLAUTH URLs sent by client. "*" allows all.
#imap_urlauth_host =

protocol imap {
# Space separated list of plugins to load (default is global mail_plugins).
#mail_plugins = $mail_plugins
mail_plugins = $mail_plugins mail_log notify

# Maximum number of IMAP connections allowed for a user from each IP address.
# NOTE: The username is compared case-sensitively.
#mail_max_userip_connections = 10
mail_max_userip_connections = 100
}

And we add mail_plugins = $mail_plugins mail_log notify

Next we will edit : vim /etc/dovecot/conf.d/10-logging.conf

# mail_log plugin provides more event logging for mail processes.
plugin {
# Events to log. Also available: flag_change append
mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename
# Available fields: uid, box, msgid, from, subject, size, vsize, flags
# size and vsize are available only for expunge and copy events.
mail_log_fields = uid box msgid size
}

to show like this.

Last step restart dovecot.

systemctl restart dovecot

Check if you get any error, in log file you will see someting like this:

Nov 10 11:25:48 imap(user@domain.com): Info: delete: box=Deleted Messages, uid=1252, msgid=<008301d22aa0$53e164e0$fba42ea0$@futuracar
go.bg>, size=11817
Nov 10 11:25:48 imap(user@domain.com): Info: delete: box=Deleted Messages, uid=1253, msgid=<01fc01d22f6f$4b3c15f0$e1b441d0$@futuracar
go.bg>, size=11402
Nov 10 11:25:48 imap(user@domain.com): Info: delete: box=Deleted Messages, uid=1254, msgid=<01f201d23112$579c7750$06d565f0$@futuracar
go.bg>, size=11396

We make this change in Centos 7.2