[Twisted-Python] SMTP with authentication

Phil Mayers p.mayers at imperial.ac.uk
Sat Nov 4 05:30:01 EST 2006

Alvin Wang wrote:
> I modified this example

You broke the example.

Try this, hopefully it is clearly what is happening:

import StringIO

from twisted.application import service

application = service.Application("SMTP Client Tutorial")

from twisted.application import internet
from twisted.python import log
from twisted.internet import defer, reactor
from twisted.mail import smtp

mailFrom = "from at example.com"
mailTo = ["to at example.com",]
mail = StringIO.StringIO("""Date: Fri, 3 Nov 2006 230:14:39 +0000
From: from at example.com
To: to at example.com
Subject: Tutorate!

Hello, how are you, goodbye.

whenDone = defer.Deferred()

def send(r):
     print "message sent:", r

whenDone.addCallbacks(sent, log.err)

def done(d):
     from twisted.internet import reactor
     reactor.callLater(1, reactor.stop)


sender = smtp.ESMTPSenderFactory(

smtpClientService = internet.TCPClient('YOURSERVER', 25, sender)

More information about the Twisted-Python mailing list