[Twisted-Python]The problem afer reactor stoped....

Alessandro aleuser at inwind.it
Tue May 6 03:09:03 EDT 2008


李祥曦 wrote:
> Hi,all
>   
Hi

>    I want to write a program that can send some e-mails automaticlly,i
> use the code like this:
>   
reactor.stop() and reactor.run() have to be called only one time!

Try the following:

def sendmail(authenticationUsername, authenticationSecret,fromAddress,
...

def sendComplete(result):
print "Message sent."
# reactor.stop() comment this line out!

class EmailUtil:
def __init__(self,popserver,smptserver,username,password):
...

def goSend(self,fromaddr, toaddr, subject, body, filenames):
...
return result.addCallbacks(sendComplete,handleError) # get back the result
# reactor.run() comment this line out

if __name__=='__main__':
twisted.internet.defer import DeferredList

f=EmailUtil('','smtp.xxx.com','xxxx','1234')
filenames=['test2.docx']
dd1 = 
f.goSend('xxxx at xxx.com','xxx at hotmail.com','testSend','aaaaaaaaaa',filenames)
dd2 = 
f.goSend('xxxx at xxx.com','xxx at hotmail.com','testSend','aaaaaaaaaa',filenames)
dd3 = 
f.goSend('xxxx at xxx.com','xxx at hotmail.com','testSend','aaaaaaaaaa',filenames)
d4ll =DeferredList([dd1,dd2,dd3]) #errback ?

def stop(*arg): reactor.stop()

d4ll.addCallback(stop)
reactor.run()


Note: not tested

You can test EmailUtil alone without twisted, removing his internal 
addCallbacks (you can attach the callback in the main)

Alessandro





More information about the Twisted-Python mailing list