python login 163 mail server

2019-03-17 10:33发布

问题:

When I use this script to login the 163 mail server,there is something wrong! My python env is python 2.7.8 Please help me!

import imaplib

def open_connect(verbose=False):
    host = 'imap.163.com'
    port = 993
    if verbose:print 'Connecting to',host
    connection = imaplib.IMAP4_SSL(host)
    username = 'tmailest@163.com'
    passwd = 'aaannnmmm'
    if verbose:print 'Logging in as',username
    try:
        connection.login(username,passwd)
    except Exception as err:
        print 'ERROR:', err

    return connection

c = open_connect()

try:
    tye,data = c.select('INBOX')
    print tye,data
    num_msgs=int(data[0])
    print 'There are %d messages in INBOX' % num_msgs
finally:
    c.close()
    c.logout()

=====

NO ['SELECT The login is not safe! Please update your mail client: http://mail.163.com/dashi']
Traceback (most recent call last):
  File "imap_select.py", line 26, in <module>
    c.close()
  File "/usr/lib/python2.7/imaplib.py", line 382, in close
    typ, dat = self._simple_command('CLOSE')
  File "/usr/lib/python2.7/imaplib.py", line 1070, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/usr/lib/python2.7/imaplib.py", line 825, in _command
    ', '.join(Commands[name])))
imaplib.error: command CLOSE illegal in state AUTH, only allowed in states SELECTED

===== And then the 163 mail server send me a mail,about this:

该行为存在以下安全隐患:
1) 邮件客户端未经有效识别,不能有效保证帐户安全性,存在帐号密码泄漏的风险;
2) 数据传输安全性低,存在数据泄漏风险。

In English is :

1) mail client not a security client 
2) data streaming is notsecruity

Thanks a lot. This is the debug info . I think that I must a have a TLS1.2 version conection.

  05:59.52 > ENFK1 LOGIN "tmailest@163.com" "aaannnmmm"
  05:59.54 < ENFK1 OK LOGIN completed
  05:59.54      matched r'(?P<tag>ENFK\d+) (?P<type>[A-Z]+) (?P<data>.*)' => ('ENFK1', 'OK', 'LOGIN completed')
  05:59.54 > ENFK2 SELECT INBOX
  05:59.54 < ENFK2 NO SELECT The login is not safe! Please update your mail client: http://mail.163.com/dashi
  05:59.54      matched r'(?P<tag>ENFK\d+) (?P<type>[A-Z]+) (?P<data>.*)' => ('ENFK2', 'NO', 'SELECT The login is not safe! Please update your mail client: http://mail.163.com/dashi')
  05:59.54 NO response: SELECT The login is not safe! Please update your mail client: http://mail.163.com/dashi
NO ['SELECT The login is not safe! Please update your mail client: http://mail.163.com/dashi']
Traceback (most recent call last):
  File "imapselect.py", line 31, in <module>
    c.close()
  File "/usr/lib64/python2.6/imaplib.py", line 375, in close
    typ, dat = self._simple_command('CLOSE')
  File "/usr/lib64/python2.6/imaplib.py", line 1060, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/usr/lib64/python2.6/imaplib.py", line 818, in _command
    ', '.join(Commands[name])))
imaplib.error: command CLOSE illegal in state AUTH, only allowed in states SELECTED

回答1:

After netease blocking your own client, they will send you an email named 网易邮箱提醒:阻止了一次不安全的收信请求 by mail@service.netease.com.

On the bottom of the email, they provided a link to the configure page:

http://config.mail.163.com/settings/imap/index.jsp?uid=YOUR_EMAIL_NAME@126.com

Replace YOUR_EMAIL_NAME by yourself.



回答2:

Netease is promoting their new mobile email app "邮箱大师", and they currently blocked any imap client other than their offical clients and several popular clients such as thunderbird, foxmail. I don't know how do they identified the client. Anyway, may it's time for you to switch to other email service provider. At least QQ mail works well.



回答3:

Please show us the debug output produced by your IMAP library. It seems that the server administrators have configured their server to always reject LOGIN even though you are on a secure SSL connection. That's an interesting choice, but some providers do that. Talk to their support about how you are supposed to connect to their service.