Setup cron to delete Exim Mail Queue

Rajesh Chauhan

Active Member
Jan 18, 2016
26
2
53
India
cPanel Access Level
Root Administrator
I have a server which is used to send lots of emails (Most system generated) I want to setup cron to delete all Exim Email Queue every day. How do I set up this thing in an easy way?
 

Eminds

Well-Known Member
Nov 10, 2016
319
32
28
India
cPanel Access Level
Root Administrator
Hello,

The emails that you are talking about must be the LFD notification emails , so instead of deleting them , check them.there might be some issue that needs to be addressed OR you can simply disable those LFD notifications from firewall option in WHM.
 

GOT

Get Proactive!
PartnerNOC
Apr 8, 2003
1,772
326
363
Chesapeake, VA
cPanel Access Level
DataCenter Provider
To answer your question directly, this command

exim -bpru | awk '{print $3}' | xargs exim -Mrm

Will delete all the messages in the queue, but it would delete a message even if it was just put in the queue a minute ago.

You might be better off changing the exim settings to dump messages out of the queue after a day. You can set this in the advanced exim config editor under the RETRYBLOCK section.
 

Rajesh Chauhan

Active Member
Jan 18, 2016
26
2
53
India
cPanel Access Level
Root Administrator
Is there any commands line for the second option?
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hello @Rajesh Chauhan

While the solution provided by @GOT will work, I do need to point out this is a terrible idea. Rather than delete potentially valid email (that your clients may be need) I'd recommend identifying the cause of the system generated emails as well as WHY they're sitting in the mail queue.


Thanks!
 
  • Like
Reactions: sparek-3

Rajesh Chauhan

Active Member
Jan 18, 2016
26
2
53
India
cPanel Access Level
Root Administrator
exim -bpru | awk '{print $3}' | xargs exim -Mrm
Is there any option to set this command to set on every day?
 

kssuhesh

Active Member
Jan 11, 2009
26
8
128
Kochi
cPanel Access Level
Root Administrator
Twitter
Hello,

You should add it in cron to run it everyday.

First, you should check the reason for generating the mails and fix it. That is the good option than deleting the emails without checking it.
 

LucasRolff

Well-Known Member
Community Guide Contributor
May 27, 2013
142
95
78
cPanel Access Level
Root Administrator
I remember once, people were complaining about the server using a lot of cached memory, they did a cronjob executing every hour, to drop caches... That was a super bad idea...

Now, this will be another bad idea :) Please just fix your email instead of clearing the queue with a cron.

Cronjobs are great, but never abuse them!