I'm trying to make a SMTP Checker using Python.
The checker will do the following things:

The code will take a list of smtps accounts (ex: host,user,pass) and will try to send an email to a email you will specify in the code. If it's successful (the send of the email)it will print the host/user/pass on the screen. If not, the code will go to the next host and so on.

I'm stuck somewhere .... I'm a beginner at Python , just 2 weeks of python learning and I can't realize where I'm doing wrong.

import sys, smtplib, socket
from smtplib import SMTP 

def printHelp(): 
    print '\nUsage: ./darkSMTPv.py <accounts>'
    print 'Ex: ./darkSMTPv.py accounts.txt'
    print '\nImportant: THE SMTP ACCOUNTS MUST BE IN THE FOLLOWING FORMAT : IP,USER,PASS\n'

# Create the message
fromaddr = "service@johndoe.com"
toaddr = "johndoe@yahoo.com"
message = """To: %s 
From: %s 
Subject: Please Update Your Account Information
 
test SMTP mail
 
""" % (toaddr,fromaddr) 

print "\n     _            _     _____ __  __ _______ _____        " 
print "    | |          | |   / ____|  \/  |__   __|  __ \       "
print "  __| | __ _ _ __| | _| (___ | \  / |  | |  | |__) |_   __"
print " / _` |/ _` | '__| |/ /\___ \| |\/| |  | |  |  ___/\ \ / /"
print "| (_| | (_| | |  |   < ____) | |  | |  | |  | |     \ V / "
print " \__,_|\__,_|_|  |_|\_\_____/|_|  |_|  |_|  |_|      \_/  "

def timer():
        now = time.localtime(time.time())
        return time.asctime(now)

if len(sys.argv) != 2: 
    printHelp() 
    exit(1) 

# Do not change anything below. 
accounts = sys.argv[1]
valid = []
currline = 0

try: 
    handle = open(accounts)
except: 
	print"\n[+] We were unable to open the SMTP filelist. Check again your path and try again."
	print"\n[+] Exiting...."

for line in handle:
	currline += 1
	
	try:
		host = line.split(':')[0]
		user = line.split(':')[1].replace('\n', '')
		password = line.split(':')[2].replace('\n', '')
	except:
		print '\n[+] We have found a error in your accounts list'
		print '\n[!] IMPORTANT: THE SMTP ACCOUNTS MUST BE IN THE FOLLOWING FORMAT : IP,USER,PASS'
		print '\n[-] Exiting....\n'
		exit(1)
	try:
		smtp = smtplib.SMTP(host)
		smtp.login(user, password)
		code = s.ehlo()[0]
		if not (200 <= code <= 299):
			code = s.helo()[0]
			if not (200 <= code <= 299):
				raise SMTPHeloError(code, resp)
		s.sendmail(fromaddr, toaddr, message)
		print "\t\n[!] Login successful:",user, password
		print "\n[!] Message Sent Successfully"
		smtp.quit()
		sys.exit(2)
	except(socket.gaierror, socket.error, socket.herror, smtplib.SMTPException), msg:
		#print "An error occurred:", msg 
		pass
		
print "[!] Ended at: " + timer() + "\n"
print "\n[!] Done!"
This question has already been answered. Start a new discussion instead.