我想按到达时间对电子邮件进行排序。
代码如下:
data = get_credential('info.txt')
imap_conn = create_connection(data, 'outlook.office365.com')
imap_conn.select('INBOX', readonly=False)
result, messages = imap_conn.sort('ARRIVAL', 'UTF-8', 'FROM peter@gmail.com SINCE "'+(datetime.date.today()-datetime.timedelta(4)).strftime('%d-%b-%Y')+'"
它返回以下错误:
File "C:\Program Files\Python37\lib\imaplib.py", line 794, in sort
typ, dat = self._simple_command(name, sort_criteria, charset, *search_criteria)
File "C:\Program Files\Python37\lib\imaplib.py", line 1196, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "C:\Program Files\Python37\lib\imaplib.py", line 1027, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.IMAP4.error: SORT command error: BAD [b'Command Error. 12']
如何解决问题?
输入字符集UTF-8
是否正确?如何从messages
获取它?
答案 0 :(得分:2)
Office365不支持SORT
扩展名。
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
在使用任何扩展名之前,您应检查CAPABILITY
。