import imaplib import sys import base64 host=sys.argv[1] port=int(sys.argv[2]) user=sys.argv[3] password=sys.argv[4] date_time=int(sys.argv[5]) mailbox=base64.b64decode(sys.argv[6]) imap_file = open(sys.argv[7],"r") tmp=imap_file.read() message=base64.b64decode(tmp) #print message imap_file.close() try: M = imaplib.IMAP4(host,port) M.login(user,password) flags="" data = M.append(mailbox,flags,date_time,message) result = data[0]+':'+data[1][0] print result #print mailbox+flags+date_time+message #M.close() #print "no errors" except imaplib.IMAP4.error, erro: print erro finally: M.logout()