imap登录测试

 1 #!/usr/bin/python
 2 # -*- coding:UTF-8 -*-
 3 
 4 import imaplib
 5 import os
 6 
 7 imap_dir = "imap_logs"
 8 if not os.path.isdir(imap_dir):
 9     os.mkdir(imap_dir)
10 
11 username = "cm2@leejay.vip"
12 password = "1"
13 mail_server = "192.168.173.14"
14 
15 i = imaplib.IMAP4_SSL(mail_server)
16 print i.login(username, password)
17 print i.select('INBOX')
18 for msg_id in i.search(None, 'ALL')[1][0].split():
19     print msg_id
20     outf = open('%s/%s.eml' % (imap_dir, msg_id), 'w')
21     outf.write(i.fetch(msg_id, '(RFC822)')[1][0][1])
22     outf.close()
23 
24 i.logout()

 

posted @ 2021-01-15 14:04  leejay_python  阅读(505)  评论(0编辑  收藏  举报