Problem occured while sending mail

Discussion in 'Python' started by sui, Sep 17, 2008.

  1. sui

    sui Guest

    this is my code

    import sys, os, glob, datetime, time
    import smtplib
    ## Parameters for SMTP session
    port=587
    SMTPserver= 'smtp.gmail.com'
    SMTPuser= ''
    pw= 'fill in here'
    SENDER= SMTPuser

    ## Message details
    FROM= SENDER
    TO= ''
    CC=FROM
    ##RECEIVERS= (TO, CC) ##proper way to send to both TO and CC
    RECEIVERS= (TO,) ## ignore the CC address

    subject= 'Test 1a'
    message='*** Email test *** '

    print 'Starting SMTP mail session on %s as %s ' %
    (SMTPserver,SMTPuser)
    session = smtplib.SMTP(SMTPserver,port)
    session.set_debuglevel(0) # set debug level to 1 to see details
    session.ehlo(SMTPuser) # say hello
    session.starttls() # TLS needed
    session.ehlo(SMTPuser) # say hello again, not sure why
    session.login(SMTPuser, pw)

    ##Create HEADER + MESSAGE
    HEADER= 'From: %s\r\n' % FROM
    HEADER= HEADER + 'To: %s\r\n' % TO
    HEADER= HEADER + 'Cc: %s\r\n' % CC
    HEADER= HEADER + 'Subject: %s\r\n' % subject
    BODY= HEADER + '\r\n' + message
    print BODY

    SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY) ## send email

    session.close()

    Now when i run this .py file...as python mail.py
    i can see only statement
    starting smtp mail......n details
    then nothing on screen after few minutes or after pressing ctrl +c
    Traceback (most recent call last):
    File "mail4.py", line 21, in <module>
    session = smtplib.SMTP(SMTPserver,port)
    File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    (code, msg) = self.connect(host, port)
    File "/usr/local/lib/python2.5/smtplib.py", line 301, in connect
    self.sock.connect(sa)
    File "<string>", line 1, in connect
    or may be conncetion time out

    wats the solution for this
     
    sui, Sep 17, 2008
    #1
    1. Advertising

  2. sui

    sui Guest

    On Sep 17, 5:04 pm, sui <> wrote:
    > this is my code
    >
    > import sys, os, glob, datetime, time
    > import smtplib
    > ## Parameters for SMTP session
    > port=587
    > SMTPserver= 'smtp.gmail.com'
    > SMTPuser= ''
    > pw= 'fill in here'
    > SENDER= SMTPuser
    >
    > ## Message details
    > FROM= SENDER
    > TO= ''
    > CC=FROM
    > ##RECEIVERS= (TO, CC) ##proper way to send to both TO and CC
    > RECEIVERS= (TO,) ## ignore the CC address
    >
    > subject= 'Test 1a'
    > message='*** Email test *** '
    >
    > print 'Starting SMTP mail session on %s as %s ' %
    > (SMTPserver,SMTPuser)
    > session = smtplib.SMTP(SMTPserver,port)
    > session.set_debuglevel(0) # set debug level to 1 to see details
    > session.ehlo(SMTPuser) # say hello
    > session.starttls() # TLS needed
    > session.ehlo(SMTPuser) # say hello again, not sure why
    > session.login(SMTPuser, pw)
    >
    > ##Create HEADER + MESSAGE
    > HEADER= 'From: %s\r\n' % FROM
    > HEADER= HEADER + 'To: %s\r\n' % TO
    > HEADER= HEADER + 'Cc: %s\r\n' % CC
    > HEADER= HEADER + 'Subject: %s\r\n' % subject
    > BODY= HEADER + '\r\n' + message
    > print BODY
    >
    > SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY) ## send email
    >
    > session.close()
    >
    > Now when i run this .py file...as python mail.py
    > i can see only statement
    > starting smtp mail......n details
    > then nothing on screen after few minutes or after pressing ctrl +c
    > Traceback (most recent call last):
    > File "mail4.py", line 21, in <module>
    > session = smtplib.SMTP(SMTPserver,port)
    > File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    > (code, msg) = self.connect(host, port)
    > File "/usr/local/lib/python2.5/smtplib.py", line 301, in connect
    > self.sock.connect(sa)
    > File "<string>", line 1, in connect
    > or may be conncetion time out
    >
    > wats the solution for this


    if i dont press cntrl + c then it shows
    Starting SMTP mail session on smtp.gmail.com as
    Traceback (most recent call last):
    File "mail4.py", line 21, in <module>
    session = smtplib.SMTP(SMTPserver,port)
    File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    (code, msg) = self.connect(host, port)
    File "/usr/local/lib/python2.5/smtplib.py", line 310, in connect
    raise socket.error, msg
    socket.error: (110, 'Connection timed out')

    plz help me its urgent.....i want to complete it as early as possible
     
    sui, Sep 17, 2008
    #2
    1. Advertising

  3. On Wed, 17 Sep 2008 05:28:05 -0700 (PDT), sui <> wrote:
    > On Sep 17, 5:04 pm, sui <> wrote:
    >> this is my code
    >>
    >> import sys, os, glob, datetime, time
    >> import smtplib
    >> ## Parameters for SMTP session
    >> port=587
    >> SMTPserver= 'smtp.gmail.com'
    >> SMTPuser= ''
    >> pw= 'fill in here'
    >> SENDER= SMTPuser
    >>
    >> ## Message details
    >> FROM= SENDER
    >> TO= ''
    >> CC=FROM
    >> ##RECEIVERS= (TO, CC) ##proper way to send to both TO and CC
    >> RECEIVERS= (TO,) ## ignore the CC address
    >>
    >> subject= 'Test 1a'
    >> message='*** Email test *** '
    >>
    >> print 'Starting SMTP mail session on %s as %s ' %
    >> (SMTPserver,SMTPuser)
    >> session = smtplib.SMTP(SMTPserver,port)
    >> session.set_debuglevel(0) # set debug level to 1 to see details
    >> session.ehlo(SMTPuser) # say hello
    >> session.starttls() # TLS needed
    >> session.ehlo(SMTPuser) # say hello again, not sure why
    >> session.login(SMTPuser, pw)
    >>
    >> ##Create HEADER + MESSAGE
    >> HEADER= 'From: %s\r\n' % FROM
    >> HEADER= HEADER + 'To: %s\r\n' % TO
    >> HEADER= HEADER + 'Cc: %s\r\n' % CC
    >> HEADER= HEADER + 'Subject: %s\r\n' % subject
    >> BODY= HEADER + '\r\n' + message
    >> print BODY
    >>
    >> SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY) ## send email
    >>
    >> session.close()
    >>
    >> Now when i run this .py file...as python mail.py
    >> i can see only statement
    >> starting smtp mail......n details
    >> then nothing on screen after few minutes or after pressing ctrl +c
    >> Traceback (most recent call last):
    >> File "mail4.py", line 21, in <module>
    >> session = smtplib.SMTP(SMTPserver,port)
    >> File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    >> (code, msg) = self.connect(host, port)
    >> File "/usr/local/lib/python2.5/smtplib.py", line 301, in connect
    >> self.sock.connect(sa)
    >> File "<string>", line 1, in connect
    >> or may be conncetion time out
    >>
    >> wats the solution for this

    >
    > if i dont press cntrl + c then it shows
    > Starting SMTP mail session on smtp.gmail.com as
    > Traceback (most recent call last):
    > File "mail4.py", line 21, in <module>
    > session = smtplib.SMTP(SMTPserver,port)
    > File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    > (code, msg) = self.connect(host, port)
    > File "/usr/local/lib/python2.5/smtplib.py", line 310, in connect
    > raise socket.error, msg
    > socket.error: (110, 'Connection timed out')
    >
    > plz help me its urgent.....i want to complete it as early as possible


    I pasted your code into a file named temp.py,
    and (perhaps superstitiously) added a backslash to this line:
    >> print 'Starting SMTP mail session on %s as %s ' %


    Here's what it does (long line wrapped manually):

    peter@eleodes:~$ python temp.py
    Starting SMTP mail session on smtp.gmail.com as
    Traceback (most recent call last):
    File "temp.py", line 27, in ?
    session.login(SMTPuser, pw)
    File "/usr/lib/python2.4/smtplib.py", line 591, in login
    raise SMTPAuthenticationError(code, resp)
    smtplib.SMTPAuthenticationError: (535, \
    '5.7.1 Username and Password not accepted. Learn more at\n' \
    '5.7.1 http://mail.google.com/support/bin/answer.py?answer=' \
    '14257 a8sm34686663poa.12')
    peter@eleodes:~$

    This indicates that it got much farther than when you ran it, since
    your timeout message comes from the smtplib.SMTP call several lines
    before the session.login call.

    As a simple connectivity test, you might see whether you can connect
    using telnet:

    peter@eleodes:~$ telnet smtp.gmail.com 587
    Trying 72.14.253.109...
    Connected to gmail-smtp.l.google.com.
    Escape character is '^]'.
    220 mx.google.com ESMTP m27sm34789033pof.6
    ^]c

    telnet> c
    Connection closed.
    peter@eleodes:~$

    --
    To email me, substitute nowhere->spamcop, invalid->net.
     
    Peter Pearson, Sep 17, 2008
    #3
  4. sui

    sui Guest

    On Sep 17, 8:04 pm, Peter Pearson <> wrote:
    > On Wed, 17 Sep 2008 05:28:05 -0700 (PDT), sui <> wrote:
    > > On Sep 17, 5:04 pm, sui <> wrote:
    > >> this is my code

    >
    > >> import sys, os, glob, datetime, time
    > >> import smtplib
    > >> ## Parameters for SMTP session
    > >> port=587
    > >> SMTPserver= 'smtp.gmail.com'
    > >> SMTPuser= ''
    > >> pw= 'fill in here'
    > >> SENDER= SMTPuser

    >
    > >> ## Message details
    > >> FROM= SENDER
    > >> TO= ''
    > >> CC=FROM
    > >> ##RECEIVERS= (TO, CC) ##proper way to send to both TO and CC
    > >> RECEIVERS= (TO,) ## ignore the CC address

    >
    > >> subject= 'Test 1a'
    > >> message='*** Email test *** '

    >
    > >> print 'Starting SMTP mail session on %s as %s ' %
    > >> (SMTPserver,SMTPuser)
    > >> session = smtplib.SMTP(SMTPserver,port)
    > >> session.set_debuglevel(0) # set debug level to 1 to see details
    > >> session.ehlo(SMTPuser) # say hello
    > >> session.starttls() # TLS needed
    > >> session.ehlo(SMTPuser) # say hello again, not sure why
    > >> session.login(SMTPuser, pw)

    >
    > >> ##Create HEADER + MESSAGE
    > >> HEADER= 'From: %s\r\n' % FROM
    > >> HEADER= HEADER + 'To: %s\r\n' % TO
    > >> HEADER= HEADER + 'Cc: %s\r\n' % CC
    > >> HEADER= HEADER + 'Subject: %s\r\n' % subject
    > >> BODY= HEADER + '\r\n' + message
    > >> print BODY

    >
    > >> SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY) ## send email

    >
    > >> session.close()

    >
    > >> Now when i run this .py file...as python mail.py
    > >> i can see only statement
    > >> starting smtp mail......n details
    > >> then nothing on screen after few minutes or after pressing ctrl +c
    > >> Traceback (most recent call last):
    > >> File "mail4.py", line 21, in <module>
    > >> session = smtplib.SMTP(SMTPserver,port)
    > >> File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    > >> (code, msg) = self.connect(host, port)
    > >> File "/usr/local/lib/python2.5/smtplib.py", line 301, in connect
    > >> self.sock.connect(sa)
    > >> File "<string>", line 1, in connect
    > >> or may be conncetion time out

    >
    > >> wats the solution for this

    >
    > > if i dont press cntrl + c then it shows
    > > Starting SMTP mail session on smtp.gmail.com as
    > > Traceback (most recent call last):
    > > File "mail4.py", line 21, in <module>
    > > session = smtplib.SMTP(SMTPserver,port)
    > > File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    > > (code, msg) = self.connect(host, port)
    > > File "/usr/local/lib/python2.5/smtplib.py", line 310, in connect
    > > raise socket.error, msg
    > > socket.error: (110, 'Connection timed out')

    >
    > > plz help me its urgent.....i want to complete it as early as possible

    >
    > I pasted your code into a file named temp.py,
    > and (perhaps superstitiously) added a backslash to this line:
    >
    > >> print 'Starting SMTP mail session on %s as %s ' %

    >
    > Here's what it does (long line wrapped manually):
    >
    > peter@eleodes:~$ python temp.py
    > Starting SMTP mail session on smtp.gmail.com as
    > Traceback (most recent call last):
    > File "temp.py", line 27, in ?
    > session.login(SMTPuser, pw)
    > File "/usr/lib/python2.4/smtplib.py", line 591, in login
    > raise SMTPAuthenticationError(code, resp)
    > smtplib.SMTPAuthenticationError: (535, \
    > '5.7.1 Username and Password not accepted. Learn more at\n' \
    > '5.7.1http://mail.google.com/support/bin/answer.py?answer='\
    > '14257 a8sm34686663poa.12')
    > peter@eleodes:~$
    >
    > This indicates that it got much farther than when you ran it, since
    > your timeout message comes from the smtplib.SMTP call several lines
    > before the session.login call.
    >
    > As a simple connectivity test, you might see whether you can connect
    > using telnet:
    >
    > peter@eleodes:~$ telnet smtp.gmail.com 587
    > Trying 72.14.253.109...
    > Connected to gmail-smtp.l.google.com.
    > Escape character is '^]'.
    > 220 mx.google.com ESMTP m27sm34789033pof.6
    > ^]c
    >
    > telnet> c
    > Connection closed.
    > peter@eleodes:~$
    >
    > --
    > To email me, substitute nowhere->spamcop, invalid->net.


    Actually i m working at place where proxy server has been
    working......so is it problem caused by that proxy server..peter thnks
    for suggestion but still its not working......
     
    sui, Sep 18, 2008
    #4
  5. sui

    sui Guest

    On Sep 17, 8:04 pm, Peter Pearson <> wrote:
    > On Wed, 17 Sep 2008 05:28:05 -0700 (PDT), sui <> wrote:
    > > On Sep 17, 5:04 pm, sui <> wrote:
    > >> this is my code

    >
    > >> import sys, os, glob, datetime, time
    > >> import smtplib
    > >> ## Parameters for SMTP session
    > >> port=587
    > >> SMTPserver= 'smtp.gmail.com'
    > >> SMTPuser= ''
    > >> pw= 'fill in here'
    > >> SENDER= SMTPuser

    >
    > >> ## Message details
    > >> FROM= SENDER
    > >> TO= ''
    > >> CC=FROM
    > >> ##RECEIVERS= (TO, CC) ##proper way to send to both TO and CC
    > >> RECEIVERS= (TO,) ## ignore the CC address

    >
    > >> subject= 'Test 1a'
    > >> message='*** Email test *** '

    >
    > >> print 'Starting SMTPmailsession on %s as %s ' %
    > >> (SMTPserver,SMTPuser)
    > >> session = smtplib.SMTP(SMTPserver,port)
    > >> session.set_debuglevel(0) # set debug level to 1 to see details
    > >> session.ehlo(SMTPuser) # say hello
    > >> session.starttls() # TLS needed
    > >> session.ehlo(SMTPuser) # say hello again, not sure why
    > >> session.login(SMTPuser, pw)

    >
    > >> ##Create HEADER + MESSAGE
    > >> HEADER= 'From: %s\r\n' % FROM
    > >> HEADER= HEADER + 'To: %s\r\n' % TO
    > >> HEADER= HEADER + 'Cc: %s\r\n' % CC
    > >> HEADER= HEADER + 'Subject: %s\r\n' % subject
    > >> BODY= HEADER + '\r\n' + message
    > >> print BODY

    >
    > >> SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY) ## send email

    >
    > >> session.close()

    >
    > >> Now when i run this .py file...as pythonmail.py
    > >> i can see only statement
    > >> starting smtpmail......n details
    > >> then nothing on screen after few minutes or after pressing ctrl +c
    > >> Traceback (most recent call last):
    > >> File "mail4.py", line 21, in <module>
    > >> session = smtplib.SMTP(SMTPserver,port)
    > >> File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    > >> (code, msg) = self.connect(host, port)
    > >> File "/usr/local/lib/python2.5/smtplib.py", line 301, in connect
    > >> self.sock.connect(sa)
    > >> File "<string>", line 1, in connect
    > >> or may be conncetion time out

    >
    > >> wats the solution for this

    >
    > > if i dont press cntrl + c then it shows
    > > Starting SMTPmailsession on smtp.gmail.com as
    > > Traceback (most recent call last):
    > > File "mail4.py", line 21, in <module>
    > > session = smtplib.SMTP(SMTPserver,port)
    > > File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    > > (code, msg) = self.connect(host, port)
    > > File "/usr/local/lib/python2.5/smtplib.py", line 310, in connect
    > > raise socket.error, msg
    > > socket.error: (110, 'Connection timed out')

    >
    > > plz help me its urgent.....i want to complete it as early as possible

    >
    > I pasted your code into a file named temp.py,
    > and (perhaps superstitiously) added a backslash to this line:
    >
    > >> print 'Starting SMTPmailsession on %s as %s ' %

    >
    > Here's what it does (long line wrapped manually):
    >
    > peter@eleodes:~$ python temp.py
    > Starting SMTPmailsession on smtp.gmail.com as
    > Traceback (most recent call last):
    > File "temp.py", line 27, in ?
    > session.login(SMTPuser, pw)
    > File "/usr/lib/python2.4/smtplib.py", line 591, in login
    > raise SMTPAuthenticationError(code, resp)
    > smtplib.SMTPAuthenticationError: (535, \
    > '5.7.1 Username and Password not accepted. Learn more at\n' \
    > '5.7.1http://mail.google.com/support/bin/answer.py?answer='\
    > '14257 a8sm34686663poa.12')
    > peter@eleodes:~$
    >
    > This indicates that it got much farther than when you ran it, since
    > your timeout message comes from the smtplib.SMTP call several lines
    > before the session.login call.
    >
    > As a simple connectivity test, you might see whether you can connect
    > using telnet:
    >
    > peter@eleodes:~$ telnet smtp.gmail.com 587
    > Trying 72.14.253.109...
    > Connected to gmail-smtp.l.google.com.
    > Escape character is '^]'.
    > 220 mx.google.com ESMTP m27sm34789033pof.6
    > ^]c
    >
    > telnet> c
    > Connection closed.
    > peter@eleodes:~$
    >
    > --
    > To email me, substitute nowhere->spamcop, invalid->net.


    even i couldnt connect using telnet....
    msg comes host is down
     
    sui, Sep 18, 2008
    #5
  6. On Wed, 17 Sep 2008 23:53:36 -0700 (PDT), sui <> wrote:
    > On Sep 17, 8:04 pm, Peter Pearson <> wrote:
    >> On Wed, 17 Sep 2008 05:28:05 -0700 (PDT), sui <> wrote:

    [snip]
    >> > socket.error: (110, 'Connection timed out')

    [snip]
    >> As a simple connectivity test, you might see whether you can connect
    >> using telnet:

    [snip]
    > even i couldnt connect using telnet....
    > msg comes host is down


    Then your problem is a networking problem. I know even less about
    networking than I know about Python. Can you ping the destination?
    Perhaps tracepath or traceroute will help you find where your
    messages are being refused. Perhaps you are trying to work through
    an internet access provider (e.g., ISP) that doesn't allow direct
    connections to remote mail servers.

    If I might add a grouchy comment, you really should learn a
    little about netiquette. When you don't bother to trim the
    quoted context or even to punctuate your text, you broadcast
    a conspicuous implication that you value your own time much
    more than you value the time of the people whose help you're
    soliciting, which is incongruous and insulting. A more
    carefully presented request might have gotten a response
    from someone more knowledgeable -- and less grouchy -- than
    me.

    --
    To email me, substitute nowhere->spamcop, invalid->net.
     
    Peter Pearson, Sep 18, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVsaWE=?=

    An error occured while...

    =?Utf-8?B?SnVsaWE=?=, Dec 1, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,254
    Lizard Man
    Aug 11, 2007
  2. Replies:
    0
    Views:
    1,467
  3. SChacko

    Error occured while running

    SChacko, Jul 13, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    505
    SChacko
    Jul 13, 2007
  4. moiseszaragoza
    Replies:
    0
    Views:
    866
    moiseszaragoza
    Dec 12, 2008
  5. glitteringsounds
    Replies:
    1
    Views:
    1,412
    Alf P. Steinbach /Usenet
    Jul 3, 2010
Loading...

Share This Page