Is there is any way to send messages to chunk of emails ID's concurrently using smptlib
Minesh Patel
minesh at gmail.com
Tue May 5 13:39:59 EDT 2009
On Mon, May 4, 2009 at 2:01 PM, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> gganesh <ganesh.gbg at gmail.com> (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='foo at bar.com'):
"""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=['to at spam.com'], message=buf)
--
Thanks,
./Minesh
More information about the Python-list
mailing list