problem in using sendmail in multi thread

2009-05-05 Thread gganesh
hi,
I'm a beginner in using Python script
I'm trying to send mails using multi-thread
I wrote



FROM = '[email protected]'
# for more mail add';' the another mail id
listTo = ['[email protected]', '[email protected]',
'[email protected]']
SUBJECT = 'This is the subject'
MSGBODY = 'This the body of the message '
MAILSERVER = 'mail..com'
port = 25
username = 'x'
password = 'x'

# trim the strings of any leading or trailing spaces
FROM = FROM.strip()
SUBJECT = SUBJECT.strip()
MSGBODY = MSGBODY.strip()
MAILSERVER = MAILSERVER.strip()
username = username.strip()
password = password.strip()



#Connect to server
print 'Connecting to mail server ', MAILSERVER
try:
s = smtplib.SMTP(MAILSERVER,port)
print 'connected'
#s.set_debuglevel(1)
except:
 print 'ERROR: Unable to connect to mail server', sys.exc_info  ()[0]
 sys.exit(1)

#login to server
if password <> '':
print 'Logging into mail server'
try:
s.login(username,password)
except:
print 'ERROR: Unable to login to mail server', MAILSERVER
print 'Please recheck your password'
sys.exit(1)

#--
print "Starting Multi Thread Method"


class MyThread(Thread):

def __init__(self, site, s, FROM, MSGBODY):
Thread.__init__(self)
self.site = site
self.s=s
self.FROM=FROM
self.MSGBODY=MSGBODY

def run(self):
print "running for %s " %self.site
s.sendmail(self.FROM, self.site, self.MSGBODY)
print "Emailed for  site %s" %self.site



a= time.time()
threads = []

for site in listTo:
T = MyThread(site,s,FROM,MSGBODY)
threads.append(T)
T.start()


for i in threads:
i.join()
s.quit()
s.close()
print "Took %s seconds" %str(time.time()-a)

#-

Error:
There is no problem with mail ids
I'm using python2.5 ,Ubuntu
I got an error like



Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in
__bootstrap_inner
self.run()
  File "threadmailmul.py", line 85, in run
s.sendmail(self.FROM, self.site, self.MSGBODY)
  File "/usr/lib/python2.5/smtplib.py", line 703, in sendmail
raise SMTPRecipientsRefused(senderrs)
SMTPRecipientsRefused: {'[email protected]': (503, '5.5.1 Error: nested
MAIL command')}

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in
__bootstrap_inner
self.run()
  File "threadmailmul.py", line 85, in run
s.sendmail(self.FROM, self.site, self.MSGBODY)
  File "/usr/lib/python2.5/smtplib.py", line 704, in sendmail
(code,resp) = self.data(msg)
  File "/usr/lib/python2.5/smtplib.py", line 487, in data
raise SMTPDataError(code,repl)
SMTPDataError: (503, '5.5.1 Error: need MAIL command')

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in
__bootstrap_inner
self.run()
  File "threadmailmul.py", line 85, in run
s.sendmail(self.FROM, self.site, self.MSGBODY)
  File "/usr/lib/python2.5/smtplib.py", line 692, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (503, '5.5.1 Error: need RCPT command',
'[email protected]')

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in
__bootstrap_inner
self.run()
  File "threadmailmul.py", line 85, in run
s.sendmail(self.FROM, self.site, self.MSGBODY)
  File "/usr/lib/python2.5/smtplib.py", line 702, in sendmail
self.rset()
  File "/usr/lib/python2.5/smtplib.py", line 453, in rset
return self.docmd("rset")
  File "/usr/lib/python2.5/smtplib.py", line 378, in docmd
return self.getreply()
  File "/usr/lib/python2.5/smtplib.py", line 355, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
SMTPServerDisconnected: Connection unexpectedly closed

Traceback (most recent call last):
  File "threadmailmul.py", line 102, in 
i.join()
  File "/usr/lib/python2.5/threading.py", line 594, in join
self.__block.wait()
  File "/usr/lib/python2.5/threading.py", line 216, in wait
waiter.acquire()


If someone could point out the (probably silly)
mistake I'm making , I would be very grateful.
Thanks in advance
--
http://mail.python.org/mailman/listinfo/python-list


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

2009-05-05 Thread 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
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem in using sendmail in multi thread

2009-05-05 Thread gganesh
On May 5, 9:25 pm, Piet van Oostrum  wrote:
> >>>>> gganesh  (g) wrote:
> >g> hi,
> >g> I'm a beginner in using Python script
> >g> I'm trying to send mails using multi-thread
> >g> I wrote
> >g> FROM = '[email protected]'
> >g> # for more mail add';' the another mail id
> >g> listTo = ['[email protected]', '[email protected]',
> >g> '[email protected]']
> >g> SUBJECT = 'This is the subject'
> >g> MSGBODY = 'This the body of the message '
> >g> MAILSERVER = 'mail..com'
> >g> port = 25
> >g> username = 'x'
> >g> password = 'x'
> >g> # trim the strings of any leading or trailing spaces
> >g> FROM = FROM.strip()
> >g> SUBJECT = SUBJECT.strip()
> >g> MSGBODY = MSGBODY.strip()
> >g> MAILSERVER = MAILSERVER.strip()
> >g> username = username.strip()
> >g> password = password.strip()
> >g> #Connect to server
> >g> print 'Connecting to mail server ', MAILSERVER
> >g> try:
> >g>       s = smtplib.SMTP(MAILSERVER,port)
>
> You can't have a single SMTP connection that's used in multiple threads.
> That is what causes the error. Each thread should have its own SMTP
> connection. So move this code (above and below) into the run() method.
>
> >g>       print 'connected'
> >g> #s.set_debuglevel(1)
> >g> except:
> >g>        print 'ERROR: Unable to connect to mail server', sys.exc_info  
> >()[0]
> >g>        sys.exit(1)
> >g> #login to server
> >g> if password <> '':
> >g>       print 'Logging into mail server'
>
> I think this try except block should be inside the if statement, i.e.
> indented 4 spaces.
>
> >g> try:
> >g>       s.login(username,password)
> >g> except:
> >g>       print 'ERROR: Unable to login to mail server', MAILSERVER
> >g>       print 'Please recheck your password'
> >g>       sys.exit(1)
> >g> #--
> >g> print "Starting Multi Thread Method"
> >g> class MyThread(Thread):
> >g>     def __init__(self, site, s, FROM, MSGBODY):
> >g>         Thread.__init__(self)
> >g>         self.site = site
> >g>       self.s=s
> >g>       self.FROM=FROM
> >g>       self.MSGBODY=MSGBODY
>
> You give the s (connection) here as a parameter, store it in self.s and
> never use that attribute.
>
> >g>     def run(self):
> >g>       print "running for %s " %self.site
> >g>       s.sendmail(self.FROM, self.site, self.MSGBODY)
>
> Here you use the global s, not self.s
>
> As I said above you should do the SMTP connection setup, including the
> login, here, and store the connection either in self.s or in a local
> variable s in the method. As you don't use the s in another method, I
> think a local variable is better.
>
> >g>       print "Emailed for  site %s" %self.site
> >g> a= time.time()
> >g> threads = []
> >g> for site in listTo:
> >g>     T = MyThread(site,s,FROM,MSGBODY)
> >g>     threads.append(T)
> >g>     T.start()
> >g> for i in threads:
> >g>     i.join()
>
> Of course the next 2 lines should also be moved to run().
>
> >g> s.quit()
> >g> s.close()
> >g> print "Took %s seconds" %str(time.time()-a)
> >g> #-
>
> --
> Piet van Oostrum 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: [email protected]


Thanks Everyone By your guidance the code worked fine
I can send mails in multi threaded environment.
Is this only way to send mails concurrently  or any other method
aviable?
regards
Ganesh







--
http://mail.python.org/mailman/listinfo/python-list


Re: problem in using sendmail in multi thread

2009-05-06 Thread gganesh
On May 6, 7:10 pm, Jean-Paul Calderone  wrote:
> On Tue, 5 May 2009 22:17:35 -0700 (PDT), gganesh  wrote:
> >On May 5, 9:25 pm, Piet van Oostrum  wrote:
> >> >>>>> gganesh  (g) wrote:
> >> >g> hi,
> >> >g> I'm a beginner in using Python script
> >> >g> I'm trying to send mails using multi-thread
> >> >g> I wrote
> >> >g> FROM = '[email protected]'
> >> >g> # for more mail add';' the another mail id
> >> >g> listTo = ['[email protected]', '[email protected]',
> >> >g> '[email protected]']
> >> >g> SUBJECT = 'This is the subject'
> >> >g> MSGBODY = 'This the body of the message '
> >> >g> MAILSERVER = 'mail..com'
> >> >g> port = 25
> >> >g> username = 'x'
> >> >g> password = 'x'
> >> >g> # trim the strings of any leading or trailing spaces
> >> >g> FROM = FROM.strip()
> >> >g> SUBJECT = SUBJECT.strip()
> >> >g> MSGBODY = MSGBODY.strip()
> >> >g> MAILSERVER = MAILSERVER.strip()
> >> >g> username = username.strip()
> >> >g> password = password.strip()
> >> >g> #Connect to server
> >> >g> print 'Connecting to mail server ', MAILSERVER
> >> >g> try:
> >> >g>       s = smtplib.SMTP(MAILSERVER,port)
>
> >> You can't have a single SMTP connection that's used in multiple threads.
> >> That is what causes the error. Each thread should have its own SMTP
> >> connection. So move this code (above and below) into the run() method.
>
> >> >g>       print 'connected'
> >> >g> #s.set_debuglevel(1)
> >> >g> except:
> >> >g>        print 'ERROR: Unable to connect to mail server', sys.exc_info  
> >> >()[0]
> >> >g>        sys.exit(1)
> >> >g> #login to server
> >> >g> if password <> '':
> >> >g>       print 'Logging into mail server'
>
> >> I think this try except block should be inside the if statement, i.e.
> >> indented 4 spaces.
>
> >> >g> try:
> >> >g>       s.login(username,password)
> >> >g> except:
> >> >g>       print 'ERROR: Unable to login to mail server', MAILSERVER
> >> >g>       print 'Please recheck your password'
> >> >g>       sys.exit(1)
> >> >g> #--
> >> >g> print "Starting Multi Thread Method"
> >> >g> class MyThread(Thread):
> >> >g>     def __init__(self, site, s, FROM, MSGBODY):
> >> >g>         Thread.__init__(self)
> >> >g>         self.site = site
> >> >g>       self.s=s
> >> >g>       self.FROM=FROM
> >> >g>       self.MSGBODY=MSGBODY
>
> >> You give the s (connection) here as a parameter, store it in self.s and
> >> never use that attribute.
>
> >> >g>     def run(self):
> >> >g>       print "running for %s " %self.site
> >> >g>       s.sendmail(self.FROM, self.site, self.MSGBODY)
>
> >> Here you use the global s, not self.s
>
> >> As I said above you should do the SMTP connection setup, including the
> >> login, here, and store the connection either in self.s or in a local
> >> variable s in the method. As you don't use the s in another method, I
> >> think a local variable is better.
>
> >> >g>       print "Emailed for  site %s" %self.site
> >> >g> a= time.time()
> >> >g> threads = []
> >> >g> for site in listTo:
> >> >g>     T = MyThread(site,s,FROM,MSGBODY)
> >> >g>     threads.append(T)
> >> >g>     T.start()
> >> >g> for i in threads:
> >> >g>     i.join()
>
> >> Of course the next 2 lines should also be moved to run().
>
> >> >g> s.quit()
> >> >g> s.close()
> >> >g> print "Took %s seconds" %str(time.time()-a)
> >> >g> #-
>
> >> --
> >> Piet van Oostrum 
> >> URL:http://pietvanoostrum.com[PGP8DAE142BE17999C4]
> >> Private email: [email protected]
>
> >Thanks Everyone By your guidance the code worked fine
> >I can send mails in multi threaded environment.
> >Is this only way to send mails concurrently  or any other method
> >aviable?
>
> Here's another way:
>
>     from twisted.mail.smtp import sendmail
>     from twisted.internet import reactor
>     from twisted.python.log import err
>
>     MAILSERVER = ...
>     listTo = [...]
>     FROM = ...
>     MSGBODY = ...
>
>     done = sendmail(MAILSERVER, FROM, listTo, MSGBODY)
>     done.addErrback(err)
>     done.addCallback(lambda ignored: reactor.stop())
>     reactor.run()
>
> Jean-Paul

Hi Jean-Paul
This is what I'm searching for ,Thanks a lot
Based on your posting I wrote a programme,but it showed me a error
like

"Failure: twisted.mail.smtp.SMTPDeliveryError: 554 No recipients
accepted"
and
"Relay access denied" errors

I can clearly figure out, that this error is because, i haven't
authenticated my email account to send mail.
I have username and password of smpt server ,how to authenticate in
Twisted Framework
--
http://mail.python.org/mailman/listinfo/python-list


About twisted.mail.smtp.SMTPDeliveryError

2009-05-08 Thread gganesh
hi group,
I wrote a code as below


from twisted.mail.smtp import sendmail
from twisted.internet import reactor
from twisted.python.log import err
import time

MAILSERVER = 'mail.xxx.com'
listTo = ['[email protected]', '[email protected]',
'[email protected]', '[email protected]']
FROM = '[email protected]'
MSGBODY = "hi this final test"
a= time.time()
done = sendmail(MAILSERVER, FROM, listTo,
MSGBODY ,senderDomainName=None, port=25)
done.addErrback(err)
done.addCallback(lambda ignored: reactor.stop())
reactor.run()
print "Took %s seconds" %str(time.time()-a)



it showed me a error
like

"Failure: twisted.mail.smtp.SMTPDeliveryError: 554 No recipients
accepted"
and
"Relay access denied" errors

Is this error is because, i haven't
authenticated my email account to send mail.
Is so , having  username and password of smpt server ,how to
authenticate in
Twisted Framework

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


AssertionError - help me to solve this in a programme with Queue

2009-05-12 Thread gganesh
Hi all,
I'm just learning python ,the code below is found in one of the
sites ,it produces an error like
Traceback (most recent call last):
  File "queue.py", line 34, in 
main()
  File "queue.py", line 28, in main
t=MyThread(q)
  File "/usr/lib/python2.5/threading.py", line 398, in __init__
assert group is None, "group argument must be None for now"
AssertionError: group argument must be None for now

can any one help me to find the reason

the code I wrote is


hosts =["http://yahoo.com";, "http://google.com";]

# create a queue class
q=Queue.Queue()

#Thread class
class MyThread(threading.Thread):
# define __int__ method acting like constructor
def __int__(self,q):
threading.Thread.__init__(self)
self.q=q
def run(self):
h=self.q.get()
opens=urllib2.urlopen(h)
print opens.read(100)

# signal the queue to say job is done
self.q.task_done()
a=time.time()
def main():
# create a pool of thread
for i in range(5):
t=MyThread(q)
t.setDaemon(True)
t.start()
for h in hosts:
queue.put(h)
q.join()
main()
print "Time elasped : %s "%(time.time()-a)


The problem may be silly ,hence I'm every new to python i need your
guidance .


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AssertionError - help me to solve this in a programme with Queue

2009-05-12 Thread gganesh
On May 12, 6:34 pm, MRAB  wrote:
> gganesh wrote:
> > Hi all,
> > I'm just learning python ,the code below is found in one of the
> > sites ,it produces an error like
> > Traceback (most recent call last):
> >   File "queue.py", line 34, in 
> >     main()
> >   File "queue.py", line 28, in main
> >     t=MyThread(q)
> >   File "/usr/lib/python2.5/threading.py", line 398, in __init__
> >     assert group is None, "group argument must be None for now"
> > AssertionError: group argument must be None for now
>
> > can any one help me to find the reason
>
> > the code I wrote is
>
> > hosts =["http://yahoo.com";, "http://google.com";]
>
> > # create a queue class
> > q=Queue.Queue()
>
> > #Thread class
> > class MyThread(threading.Thread):
> >    # define __int__ method acting like constructor
> >    def __int__(self,q):
>
>                ^^^
>                Should be __init__.
>
> >            threading.Thread.__init__(self)
> >            self.q=q
> >    def run(self):
> >            h=self.q.get()
> >            opens=urllib2.urlopen(h)
> >            print opens.read(100)
>
> >            # signal the queue to say job is done
> >            self.q.task_done()
> > a=time.time()
> > def main():
> >    # create a pool of thread
> >    for i in range(5):
> >            t=MyThread(q)
> >            t.setDaemon(True)
> >            t.start()
> >    for h in hosts:
> >            queue.put(h)
> >    q.join()
> > main()
> > print "Time elasped : %s "%(time.time()-a)
>
> > The problem may be silly ,hence I'm every new to python i need your
> > guidance .
>
>

hi
It did work that way

File "queue.py", line 15
threading.Thread__init__.(self)
 ^
SyntaxError: invalid syntax


-- 
http://mail.python.org/mailman/listinfo/python-list


what will be best framework to select to develop Multi-Level Marketing (network marketing) application in python?

2009-07-01 Thread gganesh
hi group,
I have to build a software for Multi-Level Marketing (network
marketing),There are several Frameworks available in python ,i could
like to know the best Framework suitable to develop an application on
Multi-Level Marketing .
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


simple question about Dictionary type containing List objects

2009-07-13 Thread gganesh
Hi group,
I have a dict object like
emails={'mycontacts': [ '[email protected], '[email protected]',
'[email protected]'], 'myname':['gganesh']}
I need to get the lenght of the list mycontacts ,like
mycontacts_numbers=3
help me to solve
Thanks


-- 
http://mail.python.org/mailman/listinfo/python-list