[Tutor] SMTP Module Help

Marco Petersen marco.m.petersen at gmail.com
Tue Jan 6 10:45:01 CET 2009


I'm using Python 2.5.4. I wanted to try out the SMTP module. I tried to 
send an email through my Gmail account but it keeps saying that the 
connection was refused.

This is the code that I used :

import smtplib
msg = 'Test'


server = smtplib.SMTP('smtp.gmail.com')
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login('marco.m.petersen at gmail.com', 'password')
server.sendmail('marco.m.petersen at gmail.com', 
'marcoleepetersen at gmail.com', msg)
server.close()

This error message keeps coming up:


Traceback (most recent call last):
  File "C:/Python25/send_mail.py", line 5, in <module>
    server = smtplib.SMTP('smtp.gmail.com')
  File "C:\Python25\Lib\smtplib.py", line 244, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Python25\Lib\smtplib.py", line 310, in connect
    raise socket.error, msg
error: (10061, 'Connection refused')


Can anyone help me with this?

Thanks.

-Marco


More information about the Tutor mailing list