On Mon, May 4, 2009 at 2:01 PM, Piet van Oostrum <[email protected]> wrote:
>>>>>> gganesh <[email protected]> (g) wrote:
>
>>g> Hi friends,
>>g> I suppose sendmail() can send mails one by one ,how to send mails
>>g> concurrently ,
>>g> It would be very grateful,if someone could point out a solution.
>
You can always use twisted which has an smtp library which is used for
concurrency. Not a complete working example but an understanding of
deferreds is required.
Ex:
from twisted.mail import smtp
from twisted.internet import reactor, defer
def sendEmail(to, message, subject="Testing",
_from='[email protected]'):
"""Used to send emails asyncronously to multiple recipients"""
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = _from
msg['To'] = ", ".join(to)
sending = smtp.sendmail('localhost', _from, to, msg)
sending.addCallback(sendComplete, to).addErrback(sendFailed)
def sendFailed(error):
print "Email failed: %r" % (error.getTraceback(),)
def sendComplete(result, recipients):
numDelivered, addrInfo = result
print addrInfo
if (numDelivered != len(recipients)):
log.msg(SmtpError, "Not all recipients received email %r" % addrInfo)
buf = 'TESTING'
sendEmail(to=['[email protected]'], message=buf)
--
Thanks,
./Minesh
--
http://mail.python.org/mailman/listinfo/python-list