Remove or Delete all emails message from a POP3 server
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,
- 2500: Total number of POP3 messages to remove
- telnet pop3.myisp.com 110: Telnet to ISP pop3 server and delete all emails from a POP3 server
If you are on dial-up internet connection this script is handy. If you prefer there is PHP version too .
You may also be interested in other helpful articles:
- How to remove unwanted mails from UNIX mailboxes or folders
- Linux forwarding-ports mail traffic over ssh
- How to: Linux / UNIX Delete or Remove Files With Inode Number
- How to delete a write protected file
- Linux : How to delete file securely
Discussion on This Article:
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!
Tags: bandwidth, isp, pop3_account, pop3_server, pop_server, shell_script, spam_messages, telnet_command



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.
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
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?
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
Christian,
Can you repost your script using ;<code>shell script ;<code> html tags!
thanks for the script
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?