我遇到了问题。我能够使用OpenPop在我的VB.net应用程序上阅读消息,但是由于很长时间我应该等待列出所有消息,因此我只想列出未读消息。这是C#中的documentation,这是我尝试过的,虽然出了点问题:
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)分配其值时收到错误。
答案 0 :(得分:0)
这里的问题似乎是unseenMessage
的类型不是OpenPop.Mime.Message,而是其他类型。如果您明确说明了完全限定的命名空间&类型,如下所示,这将修复类型转换错误:
Dim unseenMessage As OpenPop.Mime.Message = client.GetMessage(i + 1)
您似乎无意中导入了另一个包含Message Class的命名空间,例如:
Imports System.ServiceModel.Channels
Imports System.Web.Services.Description