About nixCraft

Topics

Remove or Delete all emails message from a POP3 server

Posted by Vivek Gite [Last updated: December 18, 2007]

My ISP provided me 5 free email ID, each with 1 GB size. However, one of the POP3 account has been spammed with over 2500+ spam messages. Getting those entire messages will not just waste my time but bandwidth too.

Sample shell script to delete all emails from POP3 server

So here is small shell script I wrote to get rid of all the messages on your POP server.

#!/bin/sh
username="me@myisp.com";
password="mypop3server-password";
MAX_MESS=$1
[ $# -eq 0 ] && exit 1 || :
sleep 2
echo USER $username
sleep 1
echo PASS $password
sleep 2
for (( j = 1 ; j <= $MAX_MESS; j++ ))
do
echo DELE $j
sleep 1
done
echo QUIT

Script usage:

First setup your POP3 username and password. Run this script as follows:
$ ./clean.pop3 2500 | telnet pop3.myisp.com 110
Output:

Trying 61.142.1xx.xxx...
Connected to pop3.myisp.com.akadns.net.
Escape character is '^]'.
+OK hello from popgate(2.34.1)
+OK password required.
+OK maildrop ready, 2501 messages (40690358 octets) (40690358 2147483648)
+OK message 1 marked deleted
+OK message 2 marked deleted
+OK message 3 marked deleted
....

Where,

If you are on dial-up internet connection this script is handy. If you prefer there is PHP version too .

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Aaron Says:

    I would like to download all my email from a POP3 server into seperate files (like what is normally done I suppose). I just need something short and sweet that will log onto server and download all messages, 1 to a file.

  2. nixcraft Says:

    Use Fetchmail to get email from POP3 mail to local Linux / UNIX a/c see url for more info:
    http://theos.in/howto-configure-fetchmail-linux-or-unix-client-program-to-fetch-emails.html

  3. RE_FreSh Says:

    With the STAT command the pop server shows how many msg’s are in the pop-mailbox. The output looks like this:

    +OK 10 74674

    where 10 stands for the numer of mails. How can i modify the script so $MAX_MESS matches the number of messages on the server?

  4. Christian Says:

    Hi, the original script not found, at least over my ubuntu 6.10

    I do some changes to correct it

    Thanks!
    chcibelli at gmail dot com

    #!/bin/bash

    username=”username”;
    password=”password”;

    MAX_MESS=$1

    [ $# -eq 0 ] && exit 1 || :

    sleep 2

    echo USER $username
    sleep 1
    echo PASS $password

    sleep 1

    for ((i=1;i

  5. nixcraft Says:

    Christian,

    Can you repost your script using ;<code&gtshell script ;<code> html tags!

  6. rupa Says:

    thanks for the script

  7. Ken G Says:

    I have about 3,800 emails to delete but there are a few genuine messages among them. Can the script be modified to delete a range?

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.