Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# imapX是否将邮件标记为已在Gmail中阅读?_C#_Imapx - Fatal编程技术网

C# imapX是否将邮件标记为已在Gmail中阅读?

C# imapX是否将邮件标记为已在Gmail中阅读?,c#,imapx,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()

我正在使用ImapX阅读Gmail电子邮件帐户,阅读后,我想将其标记为“已阅读” 据我所知,其他人在以下方面取得了成功:

ImapX.FolderCollection folders = imapclient.Folders;
ImapX.MessageCollection messages = imapclient.Folders["INBOX"].Search("UNSEEN", true); 
foreach (var mess in messages)
{
 mess.Process(); 
}
但Gmail并没有“将这些信息标记为已读”。
了解我缺少的内容吗?

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

消息的
过程
方法不会将消息标记为已读,它只下载包括附件在内的整个消息。在您的情况下,如果调用
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); 
}

我用imapx库(旧版本1)尝试了这段代码,结果没问题,只下载看不见的电子邮件,然后将其设置为“看见”。您还可以在电子邮件中检查这些活动的状态。 请注意,您必须打开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

您好,我有一个给您:为什么它不工作,我如何调试它