"smtplib.SMTPServerDisconnected: please run connect() first"

Ethan Furman ethan at stoneleaf.us
Fri Oct 9 19:02:33 EDT 2009


kj wrote:
> 
> I'm getting the error:
> 
>     smtplib.SMTPServerDisconnected: please run connect() first
> 
> when I run code that is essentially identical to the code given in
> 
>     http://docs.python.org/library/email-examples.html
> 
> The error happens at the line (copied verbatim from the example
> linked to above):
> 
> s.sendmail(me, [you], msg.as_string())
> 
> What am I doing wrong?
> 
> kynn
> 
> P.S. I'm running this using v. 2.6.1.
> 
> P.S.2. By "essentially identical" I mean that the only change I
> made to the original snippet was to initialize variables that are
> not initialized in the original (namely, textfile, me, and you)

The line preceeding it,

s = smtplib.SMTP()

needs to have an e-mail server specified.  E.g.

s = smtplib.SMTP('localhost')  # from the 2.5 docs


Hope this helps!

~Ethan~



More information about the Python-list mailing list