Ticket #5685: 5685-SMTPClient_Tutorial-20120724.patch
| File 5685-SMTPClient_Tutorial-20120724.patch, 17.9 KB (added by argonemyth, 10 months ago) |
|---|
-
doc/mail/tutorial/smtpclient/smtpclient.xhtml
71 71 <pre class="shell"> 72 72 exarkun@boson:~/mail/tutorial/smtpclient$ twistd -ny smtpclient-1.tac 73 73 18: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. 74 18:31 EST [-] using set_wakeup_fd 75 18:31 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 76 18:31 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 78 77 </pre> 79 78 80 79 <p>As we expected, not much is going on. We can shutdown this server … … 145 144 <pre class="shell"> 146 145 exarkun@boson:~/mail/tutorial/smtpclient$ twistd -ny smtpclient-2.tac 147 146 18: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 <twisted.internet.protocol.ClientFactory 153 instance at 0xb791e46c> 147 18:55 EST [-] using set_wakeup_fd 148 18:55 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 149 18:55 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 154 150 18: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 --- <exception caught here> --- 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 "/usr/bin/twistd", line 14, in <module> 152 run() 153 File "/usr/bin/twistd", line 27, in run 154 app.run(runApp, ServerOptions) 155 File "twisted/application/app.py", line 652, in run 156 runApp(config) 157 File "twisted/scripts/twistd.py", line 23, in runApp 158 SomeApplicationRunner(config).run() 159 File "twisted/application/app.py", line 390, in run 160 self.postApplication() 161 File "twisted/scripts/_twistd_unix.py", line 230, in postApplication 162 self.startApplication(self.application) 163 File "twisted/scripts/_twistd_unix.py", line 349, in startApplication 164 app.startApplication(application, not self.config['no_save']) 165 File "twisted/application/app.py", line 668, in startApplication 166 service.IService(application).startService() 167 File "twisted/application/service.py", line 282, in startService 168 service.startService() 169 File "twisted/application/internet.py", line 168, in startService 170 self._connection = self._getConnection() 171 File "twisted/application/internet.py", line 186, in _getConnection 172 'connect%s' % (self.method,))(*self.args, **self.kwargs) 173 File "twisted/internet/posixbase.py", line 470, in connectTCP 174 c = tcp.Connector(host, port, factory, timeout, bindAddress, self) 175 File "twisted/internet/tcp.py", line 1108, in __init__ 176 if abstract.isIPv6Address(host): 177 File "twisted/internet/abstract.py", line 504, in isIPv6Address 178 if '%' in addr: 179 18:55 EST [-] TypeError: argument of type 'NoneType' is not iterable 177 180 exarkun@boson:~/mail/tutorial/smtpclient$ 178 181 </pre> 179 182 … … 198 201 </pre> 199 202 200 203 <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 204 port <em>25</em>. This isn't the address we want ultimately, but it's 205 a good place-holder for the time being. If you don't have a local SMTP 206 server, 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 208 working SMTP server. We can run 209 <a href="smtpclient-3.tac">smtpclient-3.tac</a> and see what this 204 210 change gets us:</p> 205 211 206 212 <pre class="shell"> 207 213 exarkun@boson:~/mail/tutorial/smtpclient$ twistd -ny smtpclient-3.tac 208 214 19: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. 215 19:10 EST [-] using set_wakeup_fd 216 19:10 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 217 19:10 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 213 218 19:10 EST [-] Starting factory <twisted.internet.protocol.ClientFactory 214 instance at 0x b791e48c>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 callWithLogger219 instance at 0x7f76e9a7df38> 220 19:10 EST [-] [Uninitialized] Unhandled Error 221 Traceback (most recent call last): 222 File "twisted/python/log.py", line 84, in callWithLogger 218 223 return callWithContext({"system": lp}, func, *args, **kw) 219 File "twisted/python/log.py", line 41, in callWithContext224 File "twisted/python/log.py", line 69, in callWithContext 220 225 return context.call({ILogContext: newCtx}, func, *args, **kw) 221 File "twisted/python/context.py", line 52, in callWithContext226 File "twisted/python/context.py", line 118, in callWithContext 222 227 return self.currentContext().callWithContext(ctx, func, *args, **kw) 223 File "twisted/python/context.py", line 31, in callWithContext228 File "twisted/python/context.py", line 81, in callWithContext 224 229 return func(*args,**kw) 225 230 --- <exception caught here> --- 226 File "twisted/internet/ selectreactor.py", line 139, in _doReadOrWrite227 why = getattr(selectable, method)()228 File "twisted/internet/tcp.py", line 5 43, in doConnect231 File "twisted/internet/posixbase.py", line 619, in _doReadOrWrite 232 why = selectable.doWrite() 233 File "twisted/internet/tcp.py", line 581, in doConnect 229 234 self._connectDone() 230 File "twisted/internet/tcp.py", line 5 46, in _connectDone235 File "twisted/internet/tcp.py", line 595, in _connectDone 231 236 self.protocol = self.connector.buildProtocol(self.getPeer()) 232 File "twisted/internet/base.py", line 641, in buildProtocol237 File "twisted/internet/base.py", line 1049, in buildProtocol 233 238 return self.factory.buildProtocol(addr) 234 File "twisted/internet/protocol.py", line 99, in buildProtocol239 File "twisted/internet/protocol.py", line 104, in buildProtocol 235 240 p = self.protocol() 236 241 exceptions.TypeError: 'NoneType' object is not callable 237 242 238 19:10 EST [ Uninitialized] Stopping factory239 <twisted.internet.protocol.ClientFactory instance at240 0xb791e48c>243 19:10 EST [-] [Uninitialized] Stopping factory 244 <twisted.internet.protocol.ClientFactory 245 instance at 0x7f76e9a7df38> 241 246 19:10 EST [-] Received SIGINT, shutting down. 242 247 19:10 EST [-] Main loop terminated. 243 248 19:10 EST [-] Server Shut Down. … … 271 276 <pre class="shell"> 272 277 exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-4.tac 273 278 19: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. 279 19:29 EST [-] using set_wakeup_fd 280 19:29 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 281 19:29 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 278 282 19:29 EST [-] Starting factory <twisted.internet.protocol.ClientFactory 279 instance at 0xb791e4ac> 280 19:29 EST [-] Enabling Multithreading. 283 instance at 0x7fe80358ff38> 281 284 19:29 EST [-] Received SIGINT, shutting down. 282 285 19:29 EST [Protocol,client] Stopping factory 283 286 <twisted.internet.protocol.ClientFactory instance at 284 0x b791e4ac>287 0x7fe80358ff38> 285 288 19:29 EST [-] Main loop terminated. 286 289 19:29 EST [-] Server Shut Down. 287 290 exarkun@boson:~/doc/mail/tutorial/smtpclient$ … … 338 341 <pre class="shell"> 339 342 exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-5.tac 340 343 19: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. 344 19:42 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 345 19:42 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 345 346 19:42 EST [-] Starting factory <twisted.internet.protocol.ClientFactory 346 instance at 0x b791e54c>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 callWithLogger347 instance at 0x7fd5267eff38> 348 19:42 EST [Uninitialized] Unhandled Error 349 Traceback (most recent call last): 350 File "twisted/python/log.py", line 84, in callWithLogger 350 351 return callWithContext({"system": lp}, func, *args, **kw) 351 File "twisted/python/log.py", line 41, in callWithContext352 File "twisted/python/log.py", line 69, in callWithContext 352 353 return context.call({ILogContext: newCtx}, func, *args, **kw) 353 File "twisted/python/context.py", line 52, in callWithContext354 File "twisted/python/context.py", line 118, in callWithContext 354 355 return self.currentContext().callWithContext(ctx, func, *args, **kw) 355 File "twisted/python/context.py", line 31, in callWithContext356 File "twisted/python/context.py", line 81, in callWithContext 356 357 return func(*args,**kw) 357 358 --- <exception caught here> --- 358 File "twisted/internet/ selectreactor.py", line 139, in _doReadOrWrite359 why = getattr(selectable, method)()360 File "twisted/internet/tcp.py", line 5 43, in doConnect359 File "twisted/internet/posixbase.py", line 619, in _doReadOrWrite 360 why = selectable.doWrite() 361 File "twisted/internet/tcp.py", line 581, in doConnect 361 362 self._connectDone() 362 File "twisted/internet/tcp.py", line 5 46, in _connectDone363 File "twisted/internet/tcp.py", line 595, in _connectDone 363 364 self.protocol = self.connector.buildProtocol(self.getPeer()) 364 File "twisted/internet/base.py", line 641, in buildProtocol365 File "twisted/internet/base.py", line 1049, in buildProtocol 365 366 return self.factory.buildProtocol(addr) 366 File "twisted/internet/protocol.py", line 99, in buildProtocol367 File "twisted/internet/protocol.py", line 104, in buildProtocol 367 368 p = self.protocol() 368 369 exceptions.TypeError: __init__() takes at least 2 arguments (1 given) 369 370 370 371 19:42 EST [Uninitialized] Stopping factory 371 372 <twisted.internet.protocol.ClientFactory instance at 372 0x b791e54c>373 0x7fd5267eff38> 373 374 19:43 EST [-] Received SIGINT, shutting down. 374 375 19:43 EST [-] Main loop terminated. 375 376 19:43 EST [-] Server Shut Down. … … 426 427 427 428 <pre class="shell"> 428 429 exarkun@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 <__builtin__.SMTPClientFactory instance 435 at 0xb77fd68c> 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 430 07:54:15+0400 [-] Log opened. 431 07:54:15+0400 [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 432 07:54:15+0400 [-] reactor class: twisted.internet.epollreactor.EPollReactor. 433 07:54:15+0400 [-] Starting factory <__builtin__.SMTPClientFactory instance 434 at 0xcdffc8> 435 07:54:19+0400 [ESMTPClient,client] Unhandled Error 436 Traceback (most recent call last): 437 File "twisted/python/log.py", line 84, in callWithLogger 439 438 return callWithContext({"system": lp}, func, *args, **kw) 440 File "twisted/python/log.py", line 41, in callWithContext439 File "twisted/python/log.py", line 69, in callWithContext 441 440 return context.call({ILogContext: newCtx}, func, *args, **kw) 442 File "twisted/python/context.py", line 52, in callWithContext441 File "twisted/python/context.py", line 118, in callWithContext 443 442 return self.currentContext().callWithContext(ctx, func, *args, **kw) 444 File "twisted/python/context.py", line 31, in callWithContext443 File "twisted/python/context.py", line 81, in callWithContext 445 444 return func(*args,**kw) 446 445 --- <exception caught here> --- 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 452 453 why = self.lineReceived(line) 453 File "twisted/mail/smtp.py", line 10 39, in lineReceived454 File "twisted/mail/smtp.py", line 1064, in lineReceived 454 455 why = self._okresponse(self.code,'\n'.join(self.resp)) 455 File "twisted/mail/smtp.py", line 1 281, in esmtpState_serverConfig456 File "twisted/mail/smtp.py", line 1322, in esmtpState_serverConfig 456 457 self.tryTLS(code, resp, items) 457 File "twisted/mail/smtp.py", line 1 294, in tryTLS458 File "twisted/mail/smtp.py", line 1335, in tryTLS 458 459 self.authenticate(code, resp, items) 459 File "twisted/mail/smtp.py", line 13 43, in authenticate460 File "twisted/mail/smtp.py", line 1384, in authenticate 460 461 self.smtpState_from(code, resp) 461 File "twisted/mail/smtp.py", line 10 62, in smtpState_from462 File "twisted/mail/smtp.py", line 1087, in smtpState_from 462 463 self._from = self.getMailFrom() 463 File "twisted/mail/smtp.py", line 11 37, in getMailFrom464 File "twisted/mail/smtp.py", line 1173, in getMailFrom 464 465 raise NotImplementedError 465 exceptions.NotImplementedError: 466 exceptions.NotImplementedError: 466 467 467 21:17 EST [ESMTPClient,client] Stopping factory 468 <__builtin__.SMTPClientFactory instance at 0xb77fd68c>469 21:17 EST[-] Received SIGINT, shutting down.470 21:17 EST[-] Main loop terminated.471 21:17 EST[-] Server Shut Down.468 07:54:19+0400 [ESMTPClient,client] Stopping factory 469 <__builtin__.SMTPClientFactory instance at 0xcdffc8> 470 07:56:10+0400 [-] Received SIGINT, shutting down. 471 07:56:10+0400 [-] Main loop terminated. 472 07:56:10+0400 [-] Server Shut Down. 472 473 exarkun@boson:~/doc/mail/tutorial/smtpclient$ 473 474 </pre> 474 475 … … 580 581 no matter how many times you retry them), it will be between 500 and 581 582 599.</p> 582 583 584 <p>To try it, you will need to change the <code>mailTo</code> variable 585 to something real, and run the script like before! You should receive 586 the email in your Spam mailbox.</p> 587 583 588 <h3>SMTP Client 8</h3> 584 589 585 590 <p>Thus far we have succeeded in creating a Twisted client application … … 603 608 <pre class="shell"> 604 609 exarkun@boson:~/doc/mail/tutorial/smtpclient$ twistd -ny smtpclient-8.tac 605 610 19: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. 611 19:52 EST [-] twistd 12.1.0 (/usr/bin/python2.7 2.7.3) starting up. 612 19:52 EST [-] reactor class: twisted.internet.epollreactor.EPollReactor. 610 613 19:52 EST [-] Starting factory <__builtin__.SMTPClientFactory instance 611 614 at 0xb791beec> 612 19:52 EST [-] Enabling Multithreading.613 615 19:52 EST [SMTPTutorialClient,client] Sent 1 messages 614 616 19:52 EST [SMTPTutorialClient,client] Stopping factory 615 617 <__builtin__.SMTPClientFactory instance at 0xb791beec>
