Ticket #5685: 5685-SMTPClient_Tutorial-20120724.patch

File 5685-SMTPClient_Tutorial-20120724.patch, 17.9 KB (added by argonemyth, 2 years ago)
  • doc/mail/tutorial/smtpclient/smtpclient.xhtml

     
    7171<pre class="shell"> 
    7272exarkun@boson:~/mail/tutorial/smtpclient$ twistd -ny smtpclient-1.tac 
    737318:31 EST [-] Log opened. 
    74 18:31 EST [-] twistd 2.0.0 (/usr/bin/python2.4 2.4.1) starting up 
    75 18:31 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    76 18:31 EST [-] Loading smtpclient-1.tac... 
    77 18:31 EST [-] Loaded. 
     7418:31 EST [-] using set_wakeup_fd 
     7518:31 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     7618:31 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
    7877</pre> 
    7978 
    8079<p>As we expected, not much is going on.  We can shutdown this server 
     
    145144<pre class="shell"> 
    146145exarkun@boson:~/mail/tutorial/smtpclient$ twistd -ny smtpclient-2.tac 
    14714618:55 EST [-] Log opened. 
    148 18:55 EST [-] twistd SVN-Trunk (/usr/bin/python2.4 2.4.1) starting up 
    149 18:55 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    150 18:55 EST [-] Loading smtpclient-2.tac... 
    151 18:55 EST [-] Loaded. 
    152 18:55 EST [-] Starting factory &lt;twisted.internet.protocol.ClientFactory 
    153               instance at 0xb791e46c&gt; 
     14718:55 EST [-] using set_wakeup_fd  
     14818:55 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     14918:55 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
    15415018:55 EST [-] Traceback (most recent call last): 
    155           File "twisted/scripts/twistd.py", line 187, in runApp 
    156             app.runReactorWithLogging(config, oldstdout, oldstderr) 
    157           File "twisted/application/app.py", line 128, in runReactorWithLogging 
    158             reactor.run() 
    159           File "twisted/internet/posixbase.py", line 200, in run 
    160             self.mainLoop() 
    161           File "twisted/internet/posixbase.py", line 208, in mainLoop 
    162             self.runUntilCurrent() 
    163         --- &lt;exception caught here&gt; --- 
    164           File "twisted/internet/base.py", line 533, in runUntilCurrent 
    165             call.func(*call.args, **call.kw) 
    166           File "twisted/internet/tcp.py", line 489, in resolveAddress 
    167             if abstract.isIPAddress(self.addr[0]): 
    168           File "twisted/internet/abstract.py", line 315, in isIPAddress 
    169             parts = string.split(addr, '.') 
    170           File "/usr/lib/python2.4/string.py", line 292, in split 
    171             return s.split(sep, maxsplit) 
    172         exceptions.AttributeError: 'NoneType' object has no attribute 'split' 
    173  
    174 18:55 EST [-] Received SIGINT, shutting down. 
    175 18:55 EST [-] Main loop terminated. 
    176 18:55 EST [-] Server Shut Down. 
     151          File &quot;/usr/bin/twistd&quot;, line 14, in &lt;module&gt; 
     152            run() 
     153          File &quot;/usr/bin/twistd&quot;, line 27, in run 
     154            app.run(runApp, ServerOptions) 
     155          File &quot;twisted/application/app.py&quot;, line 652, in run 
     156            runApp(config) 
     157          File &quot;twisted/scripts/twistd.py&quot;, line 23, in runApp 
     158            SomeApplicationRunner(config).run() 
     159          File &quot;twisted/application/app.py&quot;, line 390, in run 
     160            self.postApplication() 
     161          File &quot;twisted/scripts/_twistd_unix.py&quot;, line 230, in postApplication 
     162            self.startApplication(self.application) 
     163          File &quot;twisted/scripts/_twistd_unix.py&quot;, line 349, in startApplication 
     164            app.startApplication(application, not self.config['no_save']) 
     165          File &quot;twisted/application/app.py&quot;, line 668, in startApplication 
     166            service.IService(application).startService() 
     167          File &quot;twisted/application/service.py&quot;, line 282, in startService 
     168            service.startService() 
     169          File &quot;twisted/application/internet.py&quot;, line 168, in startService 
     170            self._connection = self._getConnection() 
     171          File &quot;twisted/application/internet.py&quot;, line 186, in _getConnection 
     172            'connect%s' % (self.method,))(*self.args, **self.kwargs) 
     173          File &quot;twisted/internet/posixbase.py&quot;, line 470, in connectTCP 
     174            c = tcp.Connector(host, port, factory, timeout, bindAddress, self) 
     175          File &quot;twisted/internet/tcp.py&quot;, line 1108, in __init__ 
     176            if abstract.isIPv6Address(host): 
     177          File &quot;twisted/internet/abstract.py&quot;, line 504, in isIPv6Address 
     178            if '%' in addr: 
     17918:55 EST [-] TypeError: argument of type 'NoneType' is not iterable 
    177180exarkun@boson:~/mail/tutorial/smtpclient$ 
    178181</pre> 
    179182 
     
    198201</pre> 
    199202 
    200203<p>This directs the client to connect to <em>localhost</em> on 
    201 port <em>25</em>.  This isn't the address we want ultimately, but it's 
    202 a good place-holder for the time being.  We can 
    203 run <a href="smtpclient-3.tac">smtpclient-3.tac</a> and see what this 
     204port <em>25</em>. This isn't the address we want ultimately, but it's 
     205a good place-holder for the time being. If you don't have a local SMTP 
     206server, you can replace <em>localhost</em> with other SMTP servers (like 
     207<em>ASPMX.L.GOOGLE.COM</em>). The rest of the tutorial will require a 
     208working SMTP server. We can run 
     209<a href="smtpclient-3.tac">smtpclient-3.tac</a> and see what this 
    204210change gets us:</p> 
    205211 
    206212<pre class="shell"> 
    207213exarkun@boson:~/mail/tutorial/smtpclient$ twistd -ny smtpclient-3.tac 
    20821419:10 EST [-] Log opened. 
    209 19:10 EST [-] twistd SVN-Trunk (/usr/bin/python2.4 2.4.1) starting up 
    210 19:10 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    211 19:10 EST [-] Loading smtpclient-3.tac... 
    212 19:10 EST [-] Loaded. 
     21519:10 EST [-] using set_wakeup_fd  
     21619:10 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     21719:10 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
    21321819:10 EST [-] Starting factory &lt;twisted.internet.protocol.ClientFactory 
    214               instance at 0xb791e48c&gt; 
    215 19:10 EST [-] Enabling Multithreading. 
    216 19:10 EST [Uninitialized] Traceback (most recent call last): 
    217           File "twisted/python/log.py", line 56, in callWithLogger 
     219              instance at 0x7f76e9a7df38&gt; 
     22019:10 EST [-] [Uninitialized] Unhandled Error 
     221        Traceback (most recent call last): 
     222          File "twisted/python/log.py", line 84, in callWithLogger 
    218223            return callWithContext({"system": lp}, func, *args, **kw) 
    219           File "twisted/python/log.py", line 41, in callWithContext 
     224          File "twisted/python/log.py", line 69, in callWithContext 
    220225            return context.call({ILogContext: newCtx}, func, *args, **kw) 
    221           File "twisted/python/context.py", line 52, in callWithContext 
     226          File "twisted/python/context.py", line 118, in callWithContext 
    222227            return self.currentContext().callWithContext(ctx, func, *args, **kw) 
    223           File "twisted/python/context.py", line 31, in callWithContext 
     228          File "twisted/python/context.py", line 81, in callWithContext 
    224229            return func(*args,**kw) 
    225230        --- &lt;exception caught here&gt; --- 
    226           File "twisted/internet/selectreactor.py", line 139, in _doReadOrWrite 
    227             why = getattr(selectable, method)() 
    228           File "twisted/internet/tcp.py", line 543, in doConnect 
     231          File "twisted/internet/posixbase.py", line 619, in _doReadOrWrite 
     232            why = selectable.doWrite() 
     233          File "twisted/internet/tcp.py", line 581, in doConnect 
    229234            self._connectDone() 
    230           File "twisted/internet/tcp.py", line 546, in _connectDone 
     235          File "twisted/internet/tcp.py", line 595, in _connectDone 
    231236            self.protocol = self.connector.buildProtocol(self.getPeer()) 
    232           File "twisted/internet/base.py", line 641, in buildProtocol 
     237          File "twisted/internet/base.py", line 1049, in buildProtocol 
    233238            return self.factory.buildProtocol(addr) 
    234           File "twisted/internet/protocol.py", line 99, in buildProtocol 
     239          File "twisted/internet/protocol.py", line 104, in buildProtocol 
    235240            p = self.protocol() 
    236241        exceptions.TypeError: 'NoneType' object is not callable 
    237242 
    238 19:10 EST [Uninitialized] Stopping factory 
    239           &lt;twisted.internet.protocol.ClientFactory instance at 
    240           0xb791e48c&gt; 
     24319:10 EST [-] [Uninitialized] Stopping factory 
     244              &lt;twisted.internet.protocol.ClientFactory 
     245              instance at 0x7f76e9a7df38&gt; 
    24124619:10 EST [-] Received SIGINT, shutting down. 
    24224719:10 EST [-] Main loop terminated. 
    24324819:10 EST [-] Server Shut Down. 
     
    271276<pre class="shell"> 
    272277exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-4.tac 
    27327819:29 EST [-] Log opened. 
    274 19:29 EST [-] twistd SVN-Trunk (/usr/bin/python2.4 2.4.1) starting up 
    275 19:29 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    276 19:29 EST [-] Loading smtpclient-4.tac... 
    277 19:29 EST [-] Loaded. 
     27919:29 EST [-] using set_wakeup_fd 
     28019:29 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     28119:29 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
    27828219:29 EST [-] Starting factory &lt;twisted.internet.protocol.ClientFactory 
    279               instance at 0xb791e4ac&gt; 
    280 19:29 EST [-] Enabling Multithreading. 
     283              instance at 0x7fe80358ff38&gt; 
    28128419:29 EST [-] Received SIGINT, shutting down. 
    28228519:29 EST [Protocol,client] Stopping factory 
    283286          &lt;twisted.internet.protocol.ClientFactory instance at 
    284           0xb791e4ac&gt; 
     287          0x7fe80358ff38&gt; 
    28528819:29 EST [-] Main loop terminated. 
    28628919:29 EST [-] Server Shut Down. 
    287290exarkun@boson:~/doc/mail/tutorial/smtpclient$ 
     
    338341<pre class="shell"> 
    339342exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-5.tac 
    34034319:42 EST [-] Log opened. 
    341 19:42 EST [-] twistd SVN-Trunk (/usr/bin/python2.4 2.4.1) starting up 
    342 19:42 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    343 19:42 EST [-] Loading smtpclient-5.tac... 
    344 19:42 EST [-] Loaded. 
     34419:42 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     34519:42 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
    34534619:42 EST [-] Starting factory &lt;twisted.internet.protocol.ClientFactory 
    346               instance at 0xb791e54c&gt; 
    347 19:42 EST [-] Enabling Multithreading. 
    348 19:42 EST [Uninitialized] Traceback (most recent call last): 
    349           File "twisted/python/log.py", line 56, in callWithLogger 
     347              instance at 0x7fd5267eff38&gt; 
     34819:42 EST [Uninitialized] Unhandled Error 
     349        Traceback (most recent call last): 
     350          File "twisted/python/log.py", line 84, in callWithLogger 
    350351            return callWithContext({"system": lp}, func, *args, **kw) 
    351           File "twisted/python/log.py", line 41, in callWithContext 
     352          File "twisted/python/log.py", line 69, in callWithContext 
    352353            return context.call({ILogContext: newCtx}, func, *args, **kw) 
    353           File "twisted/python/context.py", line 52, in callWithContext 
     354          File "twisted/python/context.py", line 118, in callWithContext 
    354355            return self.currentContext().callWithContext(ctx, func, *args, **kw) 
    355           File "twisted/python/context.py", line 31, in callWithContext 
     356          File "twisted/python/context.py", line 81, in callWithContext 
    356357            return func(*args,**kw) 
    357358        --- &lt;exception caught here&gt; --- 
    358           File "twisted/internet/selectreactor.py", line 139, in _doReadOrWrite 
    359             why = getattr(selectable, method)() 
    360           File "twisted/internet/tcp.py", line 543, in doConnect 
     359          File "twisted/internet/posixbase.py", line 619, in _doReadOrWrite 
     360            why = selectable.doWrite() 
     361          File "twisted/internet/tcp.py", line 581, in doConnect 
    361362            self._connectDone() 
    362           File "twisted/internet/tcp.py", line 546, in _connectDone 
     363          File "twisted/internet/tcp.py", line 595, in _connectDone 
    363364            self.protocol = self.connector.buildProtocol(self.getPeer()) 
    364           File "twisted/internet/base.py", line 641, in buildProtocol 
     365          File "twisted/internet/base.py", line 1049, in buildProtocol 
    365366            return self.factory.buildProtocol(addr) 
    366           File "twisted/internet/protocol.py", line 99, in buildProtocol 
     367          File "twisted/internet/protocol.py", line 104, in buildProtocol 
    367368            p = self.protocol() 
    368369        exceptions.TypeError: __init__() takes at least 2 arguments (1 given) 
    369370 
    37037119:42 EST [Uninitialized] Stopping factory 
    371372          &lt;twisted.internet.protocol.ClientFactory instance at 
    372           0xb791e54c&gt; 
     373          0x7fd5267eff38&gt; 
    37337419:43 EST [-] Received SIGINT, shutting down. 
    37437519:43 EST [-] Main loop terminated. 
    37537619:43 EST [-] Server Shut Down. 
     
    426427 
    427428<pre class="shell"> 
    428429exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-6.tac 
    429 21:17 EST [-] Log opened. 
    430 21:17 EST [-] twistd SVN-Trunk (/usr/bin/python2.4 2.4.1) starting up 
    431 21:17 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    432 21:17 EST [-] Loading smtpclient-6.tac... 
    433 21:17 EST [-] Loaded. 
    434 21:17 EST [-] Starting factory &lt;__builtin__.SMTPClientFactory instance 
    435               at 0xb77fd68c&gt; 
    436 21:17 EST [-] Enabling Multithreading. 
    437 21:17 EST [ESMTPClient,client] Traceback (most recent call last): 
    438           File "twisted/python/log.py", line 56, in callWithLogger 
     43007:54:15+0400 [-] Log opened. 
     43107:54:15+0400 [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     43207:54:15+0400 [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
     43307:54:15+0400 [-] Starting factory &lt;__builtin__.SMTPClientFactory instance 
     434                             at 0xcdffc8&gt; 
     43507:54:19+0400 [ESMTPClient,client] Unhandled Error 
     436        Traceback (most recent call last): 
     437          File "twisted/python/log.py", line 84, in callWithLogger 
    439438            return callWithContext({"system": lp}, func, *args, **kw) 
    440           File "twisted/python/log.py", line 41, in callWithContext 
     439          File "twisted/python/log.py", line 69, in callWithContext 
    441440            return context.call({ILogContext: newCtx}, func, *args, **kw) 
    442           File "twisted/python/context.py", line 52, in callWithContext 
     441          File "twisted/python/context.py", line 118, in callWithContext 
    443442            return self.currentContext().callWithContext(ctx, func, *args, **kw) 
    444           File "twisted/python/context.py", line 31, in callWithContext 
     443          File "twisted/python/context.py", line 81, in callWithContext 
    445444            return func(*args,**kw) 
    446445        --- &lt;exception caught here&gt; --- 
    447           File "twisted/internet/selectreactor.py", line 139, in _doReadOrWrite 
    448             why = getattr(selectable, method)() 
    449           File "twisted/internet/tcp.py", line 351, in doRead 
    450             return self.protocol.dataReceived(data) 
    451           File "twisted/protocols/basic.py", line 221, in dataReceived 
     446          File "twisted/internet/posixbase.py", line 614, in _doReadOrWrite 
     447            why = selectable.doRead() 
     448          File "twisted/internet/tcp.py", line 203, in doRead 
     449            return self._dataReceived(data) 
     450          File "twisted/internet/tcp.py", line 209, in doRead 
     451            rval = self.protocol.dataReceived(data) 
     452          File "twisted/protocols/basic.py", line 564, in dataReceived 
    452453            why = self.lineReceived(line) 
    453           File "twisted/mail/smtp.py", line 1039, in lineReceived 
     454          File "twisted/mail/smtp.py", line 1064, in lineReceived 
    454455            why = self._okresponse(self.code,'\n'.join(self.resp)) 
    455           File "twisted/mail/smtp.py", line 1281, in esmtpState_serverConfig 
     456          File "twisted/mail/smtp.py", line 1322, in esmtpState_serverConfig 
    456457            self.tryTLS(code, resp, items) 
    457           File "twisted/mail/smtp.py", line 1294, in tryTLS 
     458          File "twisted/mail/smtp.py", line 1335, in tryTLS 
    458459            self.authenticate(code, resp, items) 
    459           File "twisted/mail/smtp.py", line 1343, in authenticate 
     460          File "twisted/mail/smtp.py", line 1384, in authenticate 
    460461            self.smtpState_from(code, resp) 
    461           File "twisted/mail/smtp.py", line 1062, in smtpState_from 
     462          File "twisted/mail/smtp.py", line 1087, in smtpState_from 
    462463            self._from = self.getMailFrom() 
    463           File "twisted/mail/smtp.py", line 1137, in getMailFrom 
     464          File "twisted/mail/smtp.py", line 1173, in getMailFrom 
    464465            raise NotImplementedError 
    465         exceptions.NotImplementedError: 
     466        exceptions.NotImplementedError:  
    466467 
    467 21:17 EST [ESMTPClient,client] Stopping factory 
    468           &lt;__builtin__.SMTPClientFactory instance at 0xb77fd68c&gt; 
    469 21:17 EST [-] Received SIGINT, shutting down. 
    470 21:17 EST [-] Main loop terminated. 
    471 21:17 EST [-] Server Shut Down. 
     46807:54:19+0400 [ESMTPClient,client] Stopping factory  
     469              &lt;__builtin__.SMTPClientFactory instance at 0xcdffc8&gt; 
     47007:56:10+0400 [-] Received SIGINT, shutting down. 
     47107:56:10+0400 [-] Main loop terminated. 
     47207:56:10+0400 [-] Server Shut Down. 
    472473exarkun@boson:~/doc/mail/tutorial/smtpclient$ 
    473474</pre> 
    474475 
     
    580581no matter how many times you retry them), it will be between 500 and 
    581582599.</p> 
    582583 
     584<p>To try it, you will need to change the <code>mailTo</code> variable 
     585to something real, and run the script like before! You should receive 
     586the email in your Spam mailbox.</p> 
     587 
    583588<h3>SMTP Client 8</h3> 
    584589 
    585590<p>Thus far we have succeeded in creating a Twisted client application 
     
    603608<pre class="shell"> 
    604609exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-8.tac 
    60561019:52 EST [-] Log opened. 
    606 19:52 EST [-] twistd SVN-Trunk (/usr/bin/python2.4 2.4.1) starting up 
    607 19:52 EST [-] reactor class: twisted.internet.selectreactor.SelectReactor 
    608 19:52 EST [-] Loading smtpclient-8.tac... 
    609 19:52 EST [-] Loaded. 
     61119:52 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 
     61219:52 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 
    61061319:52 EST [-] Starting factory &lt;__builtin__.SMTPClientFactory instance 
    611614              at 0xb791beec&gt; 
    612 19:52 EST [-] Enabling Multithreading. 
    61361519:52 EST [SMTPTutorialClient,client] Sent 1 messages 
    61461619:52 EST [SMTPTutorialClient,client] Stopping factory 
    615617          &lt;__builtin__.SMTPClientFactory instance at 0xb791beec&gt;