smtplib and TLS

Jp Calderone exarkun at divmod.com
Tue Jun 21 12:55:02 EDT 2005


On 21 Jun 2005 08:39:02 -0700, Matthias Kluwe <mkluwe at gmail.com> wrote:
>> From: "Paul Rubin" "http://phr.cx"@NOSPAM.invalid
>
>>> "Matthias Kluwe" <mkl... at gmail.com> writes:
>>> After getting a @gmail.com address, I recognized I had to use TLS in my
>>> python scripts using smtplib in order to get mail to the smtp.gmail.com
>>> server.
>
>>> [...]
>
>>> The server accepts and delivers my messages, but the last command
>>> raises
>
>>> socket.sslerror: (8, 'EOF occurred in violation of protocol')
>
>> [...]
>
>> Have you verified that its your end that is broken,  not gmail's,  do other
>> servers give the same response ?
>
>No, I have not -- I should have, as I know now: Connecting, starttls,
>login and sending mail works fine without the above mentioned error
>using my previous mail provider.
>
>Does that mean Gmail is in error here? I don't know...

Most SSL servers and clients (primarily HTTP, but some SMTP as well) are broken in this regard: they do not properly negotiate TLS connection shutdown.  This causes one end or the other to notice an SSL protocol error.  Most of the time, the only thing left to do after the TLS connection shutdown is normal TCP connection shutdown, so the error doesn't lead to any problems (which is probably why so much software generates this problem).  Of course, there's no way to *tell* if this is the case or not, at least programmatically.  If you receive an OK response to your DATA, you probably don't need to worry, since you have gotten what you wanted out of the conversation.

It's entirely possible that the fault here lies on gmail's end, but it is also possible that the fault is in your code or the standard library ssl support.  Unless you want to dive into Python's OpenSSL bindings or start examining network traces of SSL traffic, you probably won't be able to figure out who's to blame in this particular case.  The simplest thing to do is probably just capture and discard that particular error (again, assuming you are getting an OK resposne to your DATA command).

Jp



More information about the Python-list mailing list