I tried this code with imapx library (ver1 old version) and it rut ok, only download unseen emails then set it "seen". you also check state of these activities in your email.
NOticeL you have to turn on imapx protocol (gmail setting), and go to google account/enable 2 sms authentication/get app password to connect
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