3 from twisted.application import service
5 application = service.Application("SMTP Client Tutorial")
7 from twisted.application import internet
8 from twisted.internet import protocol
9 from twisted.mail import smtp
11 class SMTPTutorialClient(smtp.ESMTPClient):
12 mailFrom = "tutorial_sender@example.com"
13 mailTo = "tutorial_recipient@example.net"
15 Date: Fri, 6 Feb 2004 10:14:39 -0800
16 From: Tutorial Guy <tutorial_sender@example.com>
17 To: Tutorial Gal <tutorial_recipient@example.net>
20 Hello, how are you, goodbye.
23 def getMailFrom(self):
24 result = self.mailFrom
31 def getMailData(self):
32 return StringIO.StringIO(self.mailData)
34 def sentMail(self, code, resp, numOk, addresses, log):
35 print 'Sent', numOk, 'messages'
37 from twisted.internet import reactor
40 class SMTPClientFactory(protocol.ClientFactory):
41 protocol = SMTPTutorialClient
43 def buildProtocol(self, addr):
44 return self.protocol(secret=None, identity='example.com')
46 smtpClientFactory = SMTPClientFactory()
48 smtpClientService = internet.TCPClient('localhost', 25, smtpClientFactory)
49 smtpClientService.setServiceParent(application)