ikvk / imap_tools

Work with email by IMAP
Apache License 2.0
717 stars 83 forks source link

"ssl_context" and "starttls" not work #137

Closed nixiam closed 2 years ago

nixiam commented 3 years ago

Hello, meanwhile, thank you for the work you have done.

I'm having trouble using the module by forcing the ssl context.

Indeed this code works

tls_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) tls_context.set_ciphers('DEFAULT@SECLEVEL=1') server = imaplib.IMAP4(email_credentials['Host']) server.starttls(ssl_context=tls_context) server.login(email, email_credentials['Password'])

but this

tls_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) tls_context.set_ciphers('DEFAULT@SECLEVEL=1') mailbox = MailBox(email_credentials['Host'], ssl_context=tls_context, starttls=True) mailbox.login(email, email_credentials['Password'])

not work, returning "socket error: EOF" error

I'm using python 3.8.11 and imap-tools 0.46.0

TheZavitaev commented 3 years ago

Hi, Guys! Faced a similar problem Python 3.9.1 IMAP_TOOLS latest

ikvk commented 3 years ago

I have no mailbox with TLS support. Hope for info from anyone.

ghost commented 3 years ago

I got the same error earlier when I used "starttls=True" instead of "starttls=False".

starttls=True - start the conversation unencrypted and later (with the starttls command) switch to encrypted communication starttls=False - start the conversation encrypted

If you use the "starttls=True" instead of "starttls=False" your program connect to the server and try to read the IMAP server greetings but the server doesn't send it because it waits the client hello part of the SSL protocol. Finally the client return withe the "socket error: EOF" error.

ikvk commented 2 years ago

Thanks to all. If anyone see how to improve lib logic - let me know, or just do it.

ikvk commented 2 years ago

May anyone check it https://github.com/ikvk/imap_tools/pull/157 - MailBoxTls Is it good enough interface? Is it works correct?

May be someone knows public mail that supports STARTTLS?

ikvk commented 2 years ago

STARTTLS logic moved to MailBoxTls