scripting Bash to access ISP mail

I'm trying to create a small program to look at my isp and pull down the messages into individual text files. This is just a read only setup. I need to pull down the message and kill it on the server.

I'm stuck here. I have experimented with a for string but it always fails. I was trying to use date-time and the text file name and end with a .txt. I could read and delete them.

Any suggestions

#!/bin/bash
#
username="mlxxx@vabb.upn";
password="xyzpdq";
sleep 2
echo USER $username
sleep 1
echo PASS $password
sleep 2
echo STAT
sleep 1
echo QUIT
#
# cmdline string to count messages
#./getmail.sh | telnet mail.vabb.upn 110 | tail -n1 | cut -c5

---------- Post updated at 05:25 PM ---------- Previous update was at 03:49 PM ----------

here is the older version of the same code. This has the for statement that doesn't work

sleep 2
echo USER $username
sleep 1
echo PASS $password
sleep 2
echo STAT
sleep 1
#echo RETR 1
#
for i in $(seq 1 10); do echo "RETR $i">mail.txt | sleep 2 | mv mail.txt /home/otg1017/Mail/`date '+%Y%m%d-%T'`.txt ; done
sleep 2
echo QUIT

This is the command line used
# $ ./getmail.sh | telnet mail.vabb.com 110