smtplib send email by using gmail smtp server
tiefeng wu
icebergwtf at gmail.com
Sun May 3 11:18:33 EDT 2009
Hi all
I'm tring send email using smtp.gmail.com
here's the code:
*s = SMTP('**smtp.gmail.com* <http://smtp.gmail.com/>*', 25)
s.set_debuglevel(1)*
*s.ehlo()
s.starttls()
s.ehlo()
s.login(mygmailaccount, mygmailpassword)
s.sendmail(from_addr, to_addr_list, message)
s.close()*
I got the following:
*send: 'ehlo [192.168.1.104]\r\n'
reply: b'**250-mx.google.com* <http://250-mx.google.com/>* at your service,
[58.39.112.163]\r\n'
reply: b'250-SIZE 35651584\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-STARTTLS\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250 PIPELINING\r\n'
reply: retcode (250); Msg: b'**mx.google.com* <http://mx.google.com/>* at
your service, [58.39.112.163]\nSIZE 35651584\n8BITMIME\nSTARTTLS\nENHANCED
STATUSCODES\nPIPELINING'
send: 'STARTTLS\r\n'
reply: b'220 2.0.0 Ready to start TLS\r\n'
reply: retcode (220); Msg: b'2.0.0 Ready to start TLS'*
After a long time waiting I got:
*Traceback (most recent call last):
...
File "sendmail.py", line 56, in send_mail
s.starttls()
File "C:\usr\bin\python30\lib\smtplib.py", line 619, in starttls
self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
File "C:\usr\bin\python30\lib\ssl.py", line 381, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
File "C:\usr\bin\python30\lib\ssl.py", line 135, in __init__
raise x
File "C:\usr\bin\python30\lib\ssl.py", line 131, in __init__
self.do_handshake()
File "C:\usr\bin\python30\lib\ssl.py", line 327, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 8] _ssl.c:486: EOF occurred in violation of protocol*
After this I tried port 465, I got no debug messages like "send...
reply...", and after a long time waiting the following exception occured:
*Traceback (most recent call last):
...*
* File "sendmail.py", line 49, in send_mail
s = SMTP('smtp.gmail.com', 465)
File "C:\usr\bin\python30\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "C:\usr\bin\python30\lib\smtplib.py", line 296, in connect
(code, msg) = self.getreply()
File "C:\usr\bin\python30\lib\smtplib.py", line 342, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed*
Am I doing something wrong? I'm using python30 and python31a2 under Windows
XP
thanks!
Tiefeng Wu
2009-05-03
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090503/be982ebd/attachment.html>
More information about the Python-list
mailing list