tags:

views:

26

answers:

1

I'm trying to write a simple mail retrieval program in python. It seems the connection is getting established. But when I try to authorize it with the username, I don't get a reply from the server. Can anyone tell me what is going wrong here?

import socket, sys
from OpenSSL import SSL

ctx = SSL.Context(SSL.SSLv23_METHOD)

print "Creating socket"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "done"

ssl = SSL.Connection(ctx, s)

print "Establishing Connection"
ssl.connect(("pop.gmail.com", 995))
print "done"

print "Requesting Documents"
print "done"

try:
    buf = ssl.read(4096)
except SSL.ZeroReturnError:
    print "1"
sys.stdout.write(buf)

ssl.send("USER username")

try:
    buf2 = ssl.recv(4096)
except SSL.ZeroReturnError:
    print "2"
sys.stdout.write(buf2)

ssl.send("PASS secret")

try:
    buf3 = ssl.read(4096)
except SSL.ZeroReturnError:
    print "2"
sys.stdout.write(buf3)

print "connected"
ssl.close()
+1  A: 

End the string with a \r\n

tsudot