【问题标题】:In Python 3.4.3, How to send flag 'Seen' with IMAP protocol在 Python 3.4.3 中,如何使用 IMAP 协议发送标志“Seen”
【发布时间】:2017-07-15 07:55:53
【问题描述】:
  1. 获取标记为“UNSEEN”的邮件列表
  2. 阅读每封邮件
  3. 留下我制造的标志“已看到”。

我想在我的电子邮件帐户中设置一个邮件标记“已查看”。 如何在 python 中设置“Seen”标志。

你有什么想法吗?

import imaplib

emailConnection = imaplib.IMAP4_SSL() 
emailConnection.login(id, password)

emailConnection.select(configData['email_input_folder']) 

result, data = emailConnection.uid('SEARCH', None, '(UNSEEN)')
uids = data[0].split()
for uid in uids:
    result, data = emailConnection.uid('fetch', uid, '(RFC822)') 
    # ------   data is manufactured.
    result = emailConnection.store(uid, '+FLAGS', '\\Seen')  # << Occured Exception

在我的错误信息中是这样打印的。

[DEBUG|imap.py:81]2017-02-24 21:43:57,921 > STORE command error: BAD [b'Error in IMAP command STORE: Invalid messageset'] 

【问题讨论】:

    标签: python-3.x email imap


    【解决方案1】:

    您正在混合 UID 和序列集。

    如果使用UID SEARCHUID FETCH,则需要使用UID STORE

    result = emailConnection.uid("STORE", uid, '+FLAGS', '\\Seen')
    

    【讨论】:

    • 天哪,你真是个了不起的天才!非常感谢#Max。如果你不介意,你能告诉我为什么会出现这个错误吗?
    • 是的,UID 通常比序列号高得多:序列号被重复使用,但 UID 永远在增加。因此,UID 很可能不存在序列号,因此指的是不存在的消息。它给你一个错误,说它是一个错误的消息序列号。
    • 这只是python API的特性。不是吗?
    • 非常感谢。 @最大限度 。快乐黑客
    猜你喜欢
    • 1970-01-01
    • 2013-05-10
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    相关资源
    最近更新 更多