smtplib, gmail, quit vs. close and SSL3_GET_RECORD:wrong versionnumber

R

Roger

I am having a problem sending email through smtp.gmail.com using
smtplib. Everything works and the mail is sent and received, except
quit. The following shows the problem (without bothering to login or do
the sendmail):
import smtplib
server = smtplib.SMTP('smtp.gmail.com',25)
server.ehlo() (250, 'mx.google.com at your service, [68.98.218.211]\nSIZE 28311552\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES')
server.starttls() (220, '2.0.0 Ready to start TLS')
server.ehlo() (250, 'mx.google.com at your service, [68.98.218.211]\nSIZE 28311552\n8BITMIME\nAUTH LOGIN PLAIN\nENHANCEDSTATUSCODES')
server.noop() (250, '2.0.0 OK')
server.quit()

Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
server.quit()
File "c:\Python25\lib\smtplib.py", line 716, in quit
self.docmd("quit")
File "c:\Python25\lib\smtplib.py", line 378, in docmd
return self.getreply()
File "c:\Python25\lib\smtplib.py", line 352, in getreply
line = self.file.readline()
File "c:\Python25\lib\smtplib.py", line 160, in readline
chr = self.sslobj.read(1)
sslerror: (1, 'error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number')

I have not had this problem with other mail servers (but only tried
two). A solution for gmail seems to be to replace the server.quit()
with server.close(). The difference between the two commands is quit()
sends a 'QUIT' string before calling close(). Because close() is not
included in the smtplib docs, it does not appear to be the right solution.

What is the correct way to terminate a gmail session?

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top