Is there is any way to send messages to chunk of emails ID'sconcurrently using smptlib

G

gganesh

Hi friends,
I suppose sendmail() can send mails one by one ,how to send mails
concurrently ,
It would be very grateful,if someone could point out a solution.
Thanks
Ganesh
 
P

Piet van Oostrum

gganesh said:
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.

There is a discussion about this in the thread `Threaded alternatives to
smtplib?'
 
M

Minesh Patel

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='(e-mail address removed)'):
"""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=['(e-mail address removed)'], message=buf)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top