1、首先设置qq邮箱
2、开启 IMAP 服务,根据提示操作即可开启,会生成一个授权码
3、代码如下 注意搜索时候的写法
import imapclient
from datetime import date
#创建一个IMAPClient对象,大多数邮件提供商要求SSL加密,传入ssl = True关键字参数
imapObj = imapclient.IMAPClient('imap.qq.com',ssl = True)
imapObj.login('527334207@qq.com','IMAP那里生成的授权码')
imapObj.select_folder('INBOX',readonly = True)
# 读取 2020 1月1日后的未读邮件 注意写法
UIDs = imapObj.search([u'SINCE', date(2020, 1, 1),'UNSEEN'])
# 记录邮件条数
count=0
for i in UIDs:
count+=1
msgdict = imapObj.fetch(i, ['BODY[]']) # 获取邮件内容
print(msgdict)
print(count)