سؤال

I'm trying to use Python's smtplib to connect to a Dovecot server. Both seem plenty capable, but I must be missing something fundamental. Couldn't find anything in either's docs.

A non-SSL connection gets rejected right away...

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
>>> import smtplib
>>> x = smtplib.SMTP()
>>> x.set_debuglevel(True)
>>> x.connect('mail.jc-bell.com', 995)
connect: ('mail.jc-bell.com', 995)
connect: (995, 'mail.jc-bell.com')

The SSL connection seems close, but Dovecot expects something besides ehlo/helo

>>> import smtplib
>>> x = smtplib.SMTP_SSL()
>>> x.set_debuglevel(True)
>>> x.connect('mail.TheMailServer.com', 995)
connect: ('mail.TheMailServer.com', 995)
connect: ('mail.TheMailServer.com', 995)
reply: '+OK Dovecot ready.\r\n'
reply: retcode (-1); Msg: Dovecot ready.
connect: Dovecot ready.
(-1, 'Dovecot ready.')
>>> x.login('me@TheMailServer.com', '...')
send: 'ehlo my.host\r\n'
reply: '-ERR Unknown command.\r\n'
reply: retcode (-1); Msg: Unknown command.
send: 'helo my.host\r\n'
reply: '-ERR Unknown command.\r\n'
reply: retcode (-1); Msg: Unknown command.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Software\Python27\lib\smtplib.py", line 564, in login
    self.ehlo_or_helo_if_needed()
  File "C:\Software\Python27\lib\smtplib.py", line 527, in ehlo_or_helo_if_needed
    raise SMTPHeloError(code, resp)
smtplib.SMTPHeloError: (-1, 'Unknown command.')

What am I missing?

The server's certs are self-signed, but I don't think it's a CA issue because I'm getting as far as the '+OK ...'.

هل كانت مفيدة؟

المحلول

Dovecot is a POP3 / IMAP server (for checking mail). smtplib is an SMTP client (for sending mail). To connect to Dovecot, you'd want to use something like imaplib or poplib.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top