<br>Hey Senthil,<br>

<br>

Thanks for your response. <br>

My script is similar to yours, but as you've pointed that it could be
temporary. I've been re-trying to connect and send email but in vain.<br>

Here's the snippet of my code. Can you debug and help me what could really have gone wrong.<br>

____________________________________________________________________<br>

import smtplib<br>

import base64<br>

<br>

smtpserver = 'smtp.gmail.com'<br>

AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1<br>

smtpuser = 'user@gmail.com'  # for SMTP AUTH, set SMTP username here<br>

smtppass = '*****'  # for SMTP AUTH, set SMTP password here<br>

<br>

RECIPIENTS = ['someuser@gmail.com']<br>

SENDER = 'someuser@gmail.com'<br>

mssg = open('mssg.txt', 'r').read() # I am reading from this file on the same directory<br>

<br>

session = smtplib.SMTP(smtpserver,'465')<br>

session.ehlo()<br>

#session.esmtp_features["auth"] = "LOGIN PLAIN"<br>

session.connect(smtpserver,'465')<br>

session.ehlo()<br>

session.starttls()<br>

session.set_debuglevel(1)<br>

session.helo()<br>

<br>

if AUTHREQUIRED:<br>

    try:<br>

            session.login(smtpuser, smtppass)<br>

    <br>

    except SMTPAuthenticationError, e:<br>

    # if login fails, try again using a manual plain login method<br>

            smtp.docmd("AUTH LOGIN", base64.b64encode( smtpuser ))<br>

            smtp.docmd(base64.b64encode( smtppass ), "")<br>

smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)<br>

if smtpresult:<br>

    errstr = ""<br>

    for recip in smtpresult.keys():<br>

        errstr = """Could not delivery mail to: %s<br>

<br>

Server said: %s<br>

%s<br>

<br>

%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)<br>

    raise smtplib.SMTPException, errstr<br>

____________________________________________________<br>
This is the Stack Trace I got when I ran the above script after a very long time(&gt;15min)<br>
<br>
Traceback (most recent call last):<br>
  File "C:\Python26\Mail.py", line 13, in &lt;module&gt;<br>
    session = smtplib.SMTP(smtpserver,'465')<br>
  File "C:\Python26\lib\smtplib.py", line 239, in __init__<br>
    (code, msg) = self.connect(host, port)<br>
  File "C:\Python26\lib\smtplib.py", line 296, in connect<br>
    (code, msg) = self.getreply()<br>
  File "C:\Python26\lib\smtplib.py", line 340, in getreply<br>
    raise SMTPServerDisconnected("Connection unexpectedly closed")<br>
smtplib.SMTPServerDisconnected: Connection unexpectedly closed<br>
<br>
Tool completed with exit code 1<br>
<br>
______________________________________________________________________<br>

Thanks<br>

Avinash<br><blockquote><br>---------- Original message ----------<br>From:Senthil Kumaran&lt; orsenthil@gmail.com &gt;<br>Date: 11 Mar 09 09:58:53<br>Subject:  Re: [Tutor] How to send an email using Python<br>To: Samuel Avinash <samuelavinash@in.com><br><br>Hello Samuel,<br>
<br>
When sending through smtp.gmail.com you might need to starttls() and<br>
do a login() before sending.<br>
<br>
&gt;&gt;&gt; import smtplib<br>
&gt;&gt;&gt; headers = "From: %s\r
To: %s\r
Subject: %s\r
\r
" %(from,to,subject)<br>
&gt;&gt;&gt; message = headers + "Hello, How are you?"<br>
&gt;&gt;&gt; mailserver = smtplib.SMTP('smtp.gmail.com')<br>
&gt;&gt;&gt; mailserver.ehlo()<br>
&gt;&gt;&gt; mailserver.starttls()<br>
&gt;&gt;&gt; mailserver.login('username','password')<br>
&gt;&gt;&gt; mailserver.sendmail(from,to,message)<br>
<br>
As I try it now, startls() was giving me a message " reply: '454 TLS<br>
not available due to temporary reason\r
'"<br>
- As the error message says, it could be temporary.<br>
<br>
Try it at your end and report if you succeed.<br>
<br>
Thanks,<br>
Senthil<br>
<br>
On Tue, Mar 10, 2009 at 4:41 PM, Samuel Avinash <samuelavinash@in.com> wrote:<br>
&gt; Hi,<br>
&gt; Can anybody tell me how to send an email to a recipient using Python<br>
&gt; I am trying to send an email using Gmail<br>
&gt; I create an instance of  smtplib and use :<br>
&gt; x=smtplib.SMTP(sever,port)<br>
&gt; and then<br>
&gt; x.login(user,pwd)<br>
&gt; I try to send the email using<br>
&gt; x..sendmail(SENDER, RECIPIENTS, msg)<br>
&gt; But I get the following error<br>
&gt; Traceback (most recent call last):<br>
&gt; File "C:UsersAvisDesktopMail.py", line 13, in <module><br>
&gt; session = smtplib.SMTP(smtpserver,port)<br>
&gt; File "C:Python26libsmtplib.py", line 239, in __init__<br>
&gt; (code, msg) = self.connect(host, port)<br>
&gt; File "C:Python26libsmtplib.py", line 295, in connect<br>
&gt; self.sock = self._get_socket(host, port, self.timeout)<br>
&gt; File "C:Python26libsmtplib.py", line 273, in _get_socket<br>
&gt; return socket.create_connection((port, host), timeout)<br>
&gt; File "C:Python26libsocket.py", line 498, in create_connection<br>
&gt; for res in getaddrinfo(host, port, 0, SOCK_STREAM):<br>
&gt; socket.gaierror: [Errno 11001] getaddrinfo failed<br>
&gt;<br>
&gt; This is in Windows Vista and I am trying to connect to "smtp.gmail.com" with<br>
&gt; port 465<br>
&gt; _______________________________________________<br>
&gt; Tutor maillist  -  Tutor@python.org<br>
&gt; http://mail.python.org/mailman/listinfo/tutor<br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
-- <br>
-- <br>
Senthil</module></samuelavinash@in.com></samuelavinash@in.com></blockquote>