import telnetlib
import time, base64

HOST = '10.10.127.105'
#HOST = 'smtpcloud.sohu.com'
#HOST = '220.181.69.174'
category = 'postmaster@delong.sendcloud.org'
passwd = 'delong'


t1 = time.time()
tn = telnetlib.Telnet(HOST, 25) 
tn.read_until('220 ', 30) 
t2 = time.time()
tn.write('ehlo hexun.com\n')
tn.read_until('250 ', 30) 
t3 = time.time()

tn.write('AUTH LOGIN %s\n' % base64.b64encode(category))
tn.read_until('334 ', 30) 
t4 = time.time()
tn.write('%s\n' % base64.b64encode(passwd))
tn.read_until('235 ', 30) 
for i in range(33):
    t5 = time.time()
    tn.write('mail from: test@liubida.com\n')
    tn.read_until('250 ', 30) 
    t6 = time.time()
    tn.write('rcpt to: dada.chao.liu@qq.com\n')
    tn.read_until('250 ', 30) 
    t7 = time.time()
    tn.write('data\n')
    tn.read_until('354 ', 30) 
    t8 = time.time()
    tn.write('Subject: helo world %s %s \r\n' % (i, time.ctime()))
    tn.write('from: test@liubida.com\r\n')
    tn.write('to: dada.chao.liu@qq.com\r\n')
    tn.write('helo world\r\n')
    tn.write('.\r\n')
    tn.read_until('250 ', 30) 
    t9 = time.time()
    print '%.5s %.5s %.5s %.5s total:%.5s' % (t6-t5, t7-t6, t8-t7, t9-t8, t9-t1)
    time.sleep(3)

#tn.write('quit\n')


