Python,IMAP和GMail。将消息标记为SEEN [英] Python, IMAP and GMail. Mark messages as SEEN

查看:392
本文介绍了Python,IMAP和GMail。将消息标记为SEEN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本,必须提取看不见的消息,处理它,并标记为看到(或阅读)

I have a python script that has to fetch unseen messages, process it, and mark as seen (or read)

我在登录后执行此操作: p>

I do this after login in:

    typ, data = self.server.imap_server.search(None, '(UNSEEN)')

    for num in data[0].split():
        print "Mensage " + str(num) + " mark"
        self.server.imap_server.store(num, '+FLAGS', '(SEEN)')

第一个问题是,搜索返回所有消息,不仅UNSEEN 。
第二个问题是消息没有被标记为SEEN。

The first problem is that, the search returns ALL messages, and not only the UNSEEN. The second problem is that messages are not marked as SEEN.

有人可以给我一个这个吗?

Can anybody give me a hand with this?

谢谢!

推荐答案

import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com', '993')
obj.login('user', 'password')
obj.select('Inbox')   <--- it will select inbox
typ ,data = obj.search(None,'UnSeen')
obj.store(data[0].replace(' ',','),'+FLAGS','\Seen')

这篇关于Python,IMAP和GMail。将消息标记为SEEN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆