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