~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/mail/tutorial/smtpclient/smtpclient-7.tac

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import StringIO
 
2
 
 
3
from twisted.application import service
 
4
 
 
5
application = service.Application("SMTP Client Tutorial")
 
6
 
 
7
from twisted.application import internet
 
8
from twisted.internet import protocol
 
9
from twisted.mail import smtp
 
10
 
 
11
class SMTPTutorialClient(smtp.ESMTPClient):
 
12
    mailFrom = "tutorial_sender@example.com"
 
13
    mailTo = "tutorial_recipient@example.net"
 
14
    mailData = '''\
 
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>
 
18
Subject: Tutorate!
 
19
 
 
20
Hello, how are you, goodbye.
 
21
'''
 
22
 
 
23
    def getMailFrom(self):
 
24
        result = self.mailFrom
 
25
        self.mailFrom = None
 
26
        return result
 
27
 
 
28
    def getMailTo(self):
 
29
        return [self.mailTo]
 
30
 
 
31
    def getMailData(self):
 
32
        return StringIO.StringIO(self.mailData)
 
33
 
 
34
    def sentMail(self, code, resp, numOk, addresses, log):
 
35
        print 'Sent', numOk, 'messages'
 
36
 
 
37
class SMTPClientFactory(protocol.ClientFactory):
 
38
    protocol = SMTPTutorialClient
 
39
 
 
40
    def buildProtocol(self, addr):
 
41
        return self.protocol(secret=None, identity='example.com')
 
42
 
 
43
smtpClientFactory = SMTPClientFactory()
 
44
 
 
45
smtpClientService = internet.TCPClient('localhost', 25, smtpClientFactory)
 
46
smtpClientService.setServiceParent(application)