2

我面临一个问题。我可以使用 OpenPop 在我的 VB.net 应用程序上阅读消息,但我想只列出未读消息,因为我应该等待很长时间才能将它们全部列出。这是 C# 中的文档,这是我尝试过的,尽管有问题:

Dim list As New List(Of Message)
Public Function FetchUnseenMessages(ByVal hostname As String, ByVal port As Integer, useSsl As Boolean, ByVal username As String, ByVal password As String, ByVal seenUids() As String)
    Using client = New Pop3Client
        client.Connect("pop.mail.yahoo.com", "995", True)
        client.Authenticate("xxxxxxx@yahoo.com", "xxxxxxx")
        Dim uids As List(Of String) = client.GetMessageUids()
        Dim newMessages As List(Of Message) = New List(Of Message)
        For i As Integer = 0 To uids.Count Step 1
            Dim currentUidOnServer As String = uids(i)
            If Not seenUids.Contains(currentUidOnServer) Then

                Dim unseenMessage As Message = client.GetMessage(i + 1) ' error here
                newMessages.Add(unseenMessage)

            End If
        Next
    End Using
End Function

尝试声明unseenMessage为消息并使用 client.getmessage(i+1) 分配其值时出现错误。

4

1 回答 1

0

这里的问题似乎是类型unseenMessage不是OpenPop.Mime.Message,而是其他一些类型。如果显式声明完全限定的命名空间和类型,如下所示,这将修复类型转换错误:

Dim unseenMessage As OpenPop.Mime.Message = client.GetMessage(i + 1)

似乎您可能无意中导入了另一个包含消息类的命名空间,例如:

Imports System.ServiceModel.Channels
Imports System.Web.Services.Description
于 2015-10-08T13:10:16.760 回答