The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

New script now up to let you clean up your mail queue from WHM

Discussion in 'E-mail Discussions' started by PWSowner, Jul 5, 2005.

  1. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    As the title says, I have a new script now up to let you clean up your mail queue from WHM. Go to my scripts front page at http://www.premierwebsitesolutions.com/scripts/ or go right to where the new script is at http://www.premierwebsitesolutions.com/scripts/mail/.

    Upload the script to your server, set it up and add a link in your WHM, and you will be able to delete any emails sitting in the queue that match a search term you specify.

    - delete all emails from a certain domain
    - delete all emails to a certain address
    - delete all emails containing a certain phrase

    These functions can be done with the search function in shell, but this makes it easy to do from your WHM.
     
  2. punk

    punk Member

    Joined:
    Jun 20, 2002
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    thank's for your script...
    it's work :)

    is it possible to add the script to cron (of course with some addon variable to match our criteria) ?

    I think it's ussable to automaticly delete mailqueue that match our criteria

    Regards
     
  3. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Not a bad idea. I'll try to do it later today or tomorrow.
     
  4. Zaf

    Zaf Well-Known Member

    Joined:
    Aug 22, 2005
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Wish i had seen this post before, I just had 10000 mails frozen in the queue, i got down and wrote a small script to do it for me after reading a few posts here. Anyway, thanks a lot.
    EDIT: few posts here = other threads in the cpanel forums (not this)
     
    #4 Zaf, Sep 13, 2005
    Last edited: Nov 2, 2005
  5. electric

    electric Well-Known Member

    Joined:
    Nov 5, 2001
    Messages:
    697
    Likes Received:
    1
    Trophy Points:
    18
    Just a suggestion, but maybe you could submit this to the cpanel people as a possible script to include with WHM as default. It could be very handy tool!

    Thanks.
     
  6. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I told cpanel a while back that they were free to put any of my scripts into their system if they want. Any they do integrate won't have to be kept up to date by me. ;)
     
  7. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    Great script idea! We've been needing this for a while.

    Just thought I'd mention that it's better not to get into the situation where you need to clean up in the first place. I limit the number of emails someone can send per hour to a smallish number; if they need more I'm happy to up the limit, but most people don't. This way people can't clog the system up if one of their scripts runs away. (I know runaway scripts isn't the only cause of large email queues, which is where Mike's script comes in handy!!)
     
  8. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Good point, and I agree. The mail queue shouldn't need cleaning very much with proper setups and management. I almost never see more than 100 emails in my queue. The only reason I wrote the script in the first place was because once when I checked the queue, there were over 1000 emails in it, so I started looking at a few to delete the spam ones and noticed common words in many of them. That's when I thought "why not write a simple script to do the looking for me".

    I like tinkering with perl, so I like using it to automate things. :D
     
  9. Wallaby

    Wallaby Well-Known Member

    Joined:
    Aug 15, 2001
    Messages:
    131
    Likes Received:
    1
    Trophy Points:
    18
    I've implemented this script on one server and it's working great -- thanks!

    On another server, however, I got the error message "We can't seem to find one or both of the input or msglog folders"

    I checked and the exim path is indeed /var/spool/exim and the folders /var/spool/exim/input and /var/spool/exim/msglog do exist and do have the expected files in.

    However, the script is expecting /var/spool/exim/input for example to have a number of subfolders a, b, c, ... etc. This server does not have this -- all the files are in the same folder.

    So, I amended the piece of script just after the test for the input and msglog folders, as follows:

    #foreach $dir (@folders) {
    # @files = `ls -1A $exim_path/input/$dir`;
    @files = `ls -1A $exim_path/input`;
    foreach $file (@files) {
    chomp($file);
    open (FILE,"$exim_path/input/$dir/$file") or next;
    @email = <FILE>;
    close (FILE);
    foreach $line (@email) {
    if ($line =~ /$searchterm/) {
    $tmp = "$dir/$file";
    push(@todelete,$tmp);
    last;
    }
    }
    }
    #}

    to remove the loop round the subfolders.

    PWSowner -- is this the correct solution? Cheers.
     
  10. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    That should do it, although you probably found out by now. ;)
     
  11. Wallaby

    Wallaby Well-Known Member

    Joined:
    Aug 15, 2001
    Messages:
    131
    Likes Received:
    1
    Trophy Points:
    18
    Cheers Mike, it works fine with the amendment.

    *Excellent* script by the way, it helps a lot to keep our mail queues down to a reasonable size. Hope that this functionality will make it into WHM "officially" at some point.
     
  12. jackie46

    jackie46 BANNED

    Joined:
    Jul 25, 2005
    Messages:
    537
    Likes Received:
    0
    Trophy Points:
    0
    I have never ever had an issue with messages piling up in the queue. We get may 1 or 2 messeages every few days other than that we have never had this issue. I guess we are pretty efficient in weeding out all the crap that would get stuck in the queue. The only reason why i would see messages getting stuck there is if you spam filtering techniques are seriously lacking. I running the following on every box and have yet to ever see a queue pilup.

    MS + SA + Pyzor + DCC + Razor + SURBL + Mod_Sec for comment spam and illegial ip spam blocklist.
     
  13. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    True, with a good setup the mail queue should never need cleaning. I wrote this script back when blackhole was being used by default and the mail system changed, causing failed messages being sent back to pile up. Now as long as default addresses are set to fail, the queue should never get very big. I usually only have about 10 at a time in mine.

    Once in a while though, things may happen to cause the queue to grow, then it's nice to be able to clean it out without having to just delete everything.
     
  14. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    I tried it on my server but it doesn't start (impossible to show...) .
    http://61.17.76.235:2086/cgi/PWScleanmailqueue.cgi

    It works only if I execute from command line with
    perl PWScleanmailqueue.cgi

    Any idea ? Permissions are ok, root:root 700 uploaded with ASCII mode.


    Thank you
     
    #14 Radio_Head, Nov 6, 2005
    Last edited: Nov 14, 2005
  15. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    PM me if you want me to take a look.

     
  16. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I now have a cron job version. You set some search terms in a data file and run the modified version of the script on a regular basis to automatically clean up the mail queue.
    Custom Scripts

    Just remember, if your mail queue is out of control, it means there is something that needs to be looked at. Under normal conditions that should not be a problem, but even under normal conditions, there are always junk emails there and it's nice to get rid of them.
     
  17. yawsh

    yawsh Well-Known Member

    Joined:
    Jun 20, 2004
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    6
    Great.

    Is there any script which will delete queued un-sent msg which exceeds 24 hours. (give time limitation).
     
  18. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    The cron job version can pretty much do that by setting the variables in the text file.
     
  19. Zaf

    Zaf Well-Known Member

    Joined:
    Aug 22, 2005
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16

    exiqgrep -i -o 86400 | xargs exim -Mrm


    hth
     
  20. claudio

    claudio Well-Known Member

    Joined:
    Jul 31, 2004
    Messages:
    201
    Likes Received:
    0
    Trophy Points:
    16
    guys this scripts are really cool

    these days i am working in a very similar script to count all mail queue and send me an email each hour so i can know if there is a lot of mail stucked in the queue maybe a spam is occouring

    congratulations on this thread

    Claudio
     
Loading...

Share This Page