英文:
Error connecting IMAP server with python imaplib and mailcow
问题
我刚刚在一个刚刚安装的Ubuntu 22.04 VPS上安装了mailcow邮件服务器。可以通过Evolution成功连接,但是尝试使用Python脚本使用imaplib连接时出现问题。客户端是Ubuntu 22.10 Mate,Python版本是3.10。
import imaplib
imap = imaplib.IMAP4_SSL("mail.mysite.com", 143)
imap.login('me@mysite.com', 'a_strong_password')
出现错误:
Traceback (most recent call last):
File "/home/cc1/python/mail/imap_test.py", line 12, in <module>
imap = imaplib.IMAP4_SSL("mail.mysite.com", 143)
File "/usr/lib/python3.10/imaplib.py", line 1323, in __init__
IMAP4.__init__(self, host, port, timeout)
...
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)
我尝试过使用ssl context的不同选项,但都没有成功。这是我的邮件客户端的配置,可以正常工作:mail client。我猜这可能与服务器端配置有关,但我对mailcow和dovecot都不太熟悉。
英文:
I just install a mailcow mail server on a ubuntu 22.04(fresh install) vps, i can connect well with my mail client (Evolution), but have issue when trying to connect from a python script using imaplib:
my client side is Ubuntu 22.10 Mate with Python 3.10
import imaplib
imap = imaplib.IMAP4_SSL("mail.mysite.com", 143)
imap.login('me@mysite.com','a_strong_password')
getting this error:
Traceback (most recent call last):
File "/home/cc1/python/mail/imap_test.py", line 12, in <module>
imap = imaplib.IMAP4_SSL("mail.mysite.com", 143)
File "/usr/lib/python3.10/imaplib.py", line 1323, in __init__
IMAP4.__init__(self, host, port, timeout)
File "/usr/lib/python3.10/imaplib.py", line 202, in __init__
self.open(host, port, timeout)
File "/usr/lib/python3.10/imaplib.py", line 1336, in open
IMAP4.open(self, host, port, timeout)
File "/usr/lib/python3.10/imaplib.py", line 312, in open
self.sock = self._create_socket(timeout)
File "/usr/lib/python3.10/imaplib.py", line 1327, in _create_socket
return self.ssl_context.wrap_socket(sock,
File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.10/ssl.py", line 1071, in _create
self.do_handshake()
File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)
I already try using ssl context with both options:
# PROTOCOL_SSLv23
# PROTOCOL_TLS
# PROTOCOL_TLS_CLIENT
# PROTOCOL_TLSv1
# PROTOCOL_TLSv1_1
# PROTOCOL_TLSv1_2
here the config of my mail client working well:
mail client
i guess its about some server side config, but i'm new to mailcow and dovecot
答案1
得分: 1
只需找出我的问题:
将
imap = imaplib.IMAP4_SSL("mail.mysite.com", 143)
替换为
imap = imaplib.IMAP4_SSL("mail.mysite.com")
然后它就可以正常工作。
英文:
Just find out my problem:
replacing
imap = imaplib.IMAP4_SSL("mail.mysite.com", 143)
by
imap = imaplib.IMAP4_SSL("mail.mysite.com")
and then it works well
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论