namit
namit

Reputation: 113

smtp telnet python

Having some issues getting back results from telnet library but all I am getting is header and then blank waiting for input.

Any idea how can get the output from Telnet?

def smtp_test(server_info):
print "Check server info: " + server_info
cpos = server_info.find(':')
try:
    sock = socket()
    # sock.connect((server_info[:cpos], int(server_info[cpos+1:])))
    sock.connect(("mail.SMTPSERVERNAME.com", 25))
    print sock.recv(256)
    sock.send("HELO client.example.com\r")
    print sock.recv(256)
    sock.send("MAIL from: <[email protected]>\r")
    print sock.recv(256)
    #sock.send("RCPT to: <[email protected]>")
    #print sock.recv(256)
    sock.close
    return True
except:
    return False

Upvotes: 0

Views: 3394

Answers (1)

mata
mata

Reputation: 69042

\r isn't the line terminator. therefore the server doesn't reply and waits util he sees a full line, while you wait for a reply from the server. classic deadlock.

try using \r\n.

and you should consider using smtplib instead.

Upvotes: 2

Related Questions