views:

975

answers:

3

I'm having difficulty getting python 2.4 to connect to gmail's smtp server. My below script doesn't ever get past "connection". I realise there is an SMTP_SSL class in later versions of python and it seems to work fine, but the production environment I have to deal with only has - and likely will only ever have - python 2.4.

print "connecting"
server = smtplib.SMTP("smtp.gmail.com", 465)

print "ehlo"
server.ehlo()
print "start tls"
server.starttls()

print "ehlo"
server.ehlo()
print "log in"
if self.smtpuser:
    server.login(smtpuser, smtppassword)

Does anybody have any advice for getting the above code to work with python 2.4?

+2  A: 

When I tried setting something similar up for Django apps, I could never get it to work on port 465. Using port 587, which is the other port listed in the GMail docs seemed to work.

Dominic Rodger
Or for some setups, the default (25) works.
Matthew Flaschen
+1  A: 

Yes I used 587 as the port for my vb.net app too. 465 did not work for me too.

Shoban
+1  A: 

try

server.ehlo('[email protected]')

in both places above

also look at setting

server.set_debuglevel(1) value as required for more info