Here's a simple example of an email thread (not tested, hacked out of some code I
have):
#
# email sender
#
from MimeMail import faktMimeMail
import threading
class emailsender(threading.Thread):
def __init__(self,to_addr,cc,from,subject,body,server):
self.to_addr = to_addr
self.cc = cc
self.from = from
self.subject = subject
self.body = body
self.server = server
def run(self):
mail = faktMimeMail()
mail.To(self.to_addr)
mail.CC(self.cc)
mail.From(self.from)
mail.Subject(self.subject)
mail.Body(self.body)
mail.BodyHTML(self.body)
mail.Send(self.server)
then in my servlet here's some of the code :
def myservlet(Page):
def submit(self):
'''Standard WebKit "action" method; to be run if button "submit" is clicked'''
if self.form.isSuccessful(): #using FormKit here
emailAddr = self.request().field('email', '')
body = "here's the body"
...
from myutils.emailsender import emailsender
emailthread = emailsender(emailAddr,None,'[EMAIL PROTECTED]','Here's your
email',body,'<mail server name>')
emailthread.start()
The emailthread starts when you call start() and finishes when done but in the
meantime your servlet doesn't wait - it just "fires and forgets" so you don't have to
wait for it to complete. When done the emailthread will die itself.
-----Original Message-----
From: Uzo Uzo [mailto:[EMAIL PROTECTED]
Sent: Monday, October 13, 2003 11:40 AM
To: [EMAIL PROTECTED]
Subject: RE: [Webware-discuss] sending email locking my application
how do I spawn a new thread?
--- Ian Sparks <[EMAIL PROTECTED]> wrote:
>
> Uzo wrote :
> >>
> A certain part of my web application sends out
> email,
> for whatever reason, when I reached this part
> webware
> locked up,
> <<
>
> It should only lock up for the request (thread) that
> it is processing, other requests should still be
> handled.
>
> In any case, you might want to consider displaying
> or directing the user to a page that says "Your
> email has been sent" while you spawn a new thread
> that will deal with the email. That way, the user
> doesn't have to wait while the email is actually
> sent. Of course, doing things this way does mean
> that if the email fails you can't report that to the
> user....
>
>
>
>
>
>
-------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback
> Program.
> SourceForge.net hosts over 70,000 Open Source
> Projects.
> See the people who have HELPED US provide better
> services:
> Click here: http://sourceforge.net/supporters.php
> _______________________________________________
> Webware-discuss mailing list
> [EMAIL PROTECTED]
>
https://lists.sourceforge.net/lists/listinfo/webware-discuss
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss