imapX将邮件标记为已在Gmail中读取?

时间:2013-06-03 19:44:15

标签: c# imapx

我正在使用ImapX阅读Gmail电子邮件帐户,在阅读之后,我想将其标记为“已读” 据我了解,其他人已成功:

ImapX.FolderCollection folders = imapclient.Folders;
ImapX.MessageCollection messages = imapclient.Folders["INBOX"].Search("UNSEEN", true); 
foreach (var mess in messages)
{
 mess.Process(); 
}

但Gmail不是“将这些邮件标记为已读”。 对我缺少什么的任何见解?

2 个答案:

答案 0 :(得分:1)

首先,如果您使用旧的ImapX库,我邀请您升级到ImapX 2。它正在不断发展和支持。还有所有常见操作的示例代码。

邮件的Process方法不会将邮件标记为已读,只会下载包含附件的整个邮件。在您的情况下,如果您调用Search方法将第二个参数设置为true,则不必为每条消息调用它。

要将邮件标记为已读,只需使用邮件的AddFlag方法:

ImapX.Collections.FolderCollection folders = imapclient.Folders;
ImapX.Collections.MessageCollection messages = imapclient.Folders["INBOX"].Search("UNSEEN", true); 
foreach (var mess in messages)
{
    mess.AddFlag(ImapX.Flags.MessageFlags.Seen); 
}

答案 1 :(得分:0)

我在imapx库(ver1旧版本)中尝试了此代码,它很正常,只下载看不见的电子邮件,然后将其设置为“ seen”。您还可以在电子邮件中检查这些活动的状态。 注意,您必须打开imapx协议(gmail设置),然后转到Google帐户/启用2个短信验证/获取应用密码进行连接

Dim client As New ImapX.ImapClient("imap.gmail.com", 993, True)
    Dim result As Boolean = client.Connection()
    If result Then
        result = client.LogIn("id@gmail.com", "gmail password")
        If result Then
            MessageBox.Show("Log on successful", "Status...", MessageBoxButtons.OK, MessageBoxIcon.Information)
            MessageBox.Show("Please wait for some minutes...", "Status...", MessageBoxButtons.OK, MessageBoxIcon.Information)


            For Each m As ImapX.Message In client.Folders("INBOX").Search("UNSEEN", True)


                If check_stop_read_email = True Then
                    client.LogOut()
                    check_stop_read_email = False
                    Exit For
                End If

                Threading.Thread.Sleep(1000)
                DoEvents()

                Try
                    m.Process()
                Catch ex As Exception
                    Continue For
                End Try

                'Email content is m.HtmlBody.TextData
                'Subject is m.Subject


                m.SetFlag(ImapX.ImapFlags.SEEN)
                DoEvents()

            Next
            client.LogOut()
            MessageBox.Show("Done!")
        Else
            MessageBox.Show("Wrong username or password", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        MessageBox.Show("Connection_Failed", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If