Sample code for 30+ languages & platforms
VB.NET Requires Chilkat v11.0.0+

POP3 Implicit TLS: Gmail OAuth2 on Port 995

Authenticate to Gmail on port 995 with implicit TLS and inspect headers for up to ten currently available POP messages. UIDLs stay as strings. With headerOnly=true, a zero line-count argument retrieves headers plus the first body line. The example displays only headers and issues TOP, neither RETR nor DELE.

Enable POP in Gmail settings and review the option controlling Gmail's copy after access. Delivery windows, history, and batching mean available POP mail is not the entire Gmail mailbox. Use IMAP for folder/label access and synchronization.

First authorize the mailbox for https://mail.google.com/ and refresh the token as needed. Read the current token from gmail-mail-token.json in a private working directory. Narrow Gmail REST scopes do not authorize these protocols. Keep the token and authentication logs private.

Implicit TLS starts when the TCP connection opens. It is different from STLS on port 110. The historical password-based Gmail sample has been replaced with OAuth2.

See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.

Reference documentation

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim token As New Chilkat.JsonObject
success = token.LoadFile("gmail-mail-token.json")
If (success <> True) Then
    Debug.WriteLine("Could not read gmail-mail-token.json from the private working directory.")
    Exit Sub
End If

If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",True) = True)) Then
    Debug.WriteLine("An OAuth access token is required. Authorize or refresh the account first.")
    Exit Sub
End If

Dim mailbox As String = "user@example.com"
Dim mailman As New Chilkat.MailMan
mailman.MailHost = "pop.gmail.com"
mailman.MailPort = 995
mailman.PopSsl = True
mailman.RequireSslCertVerify = True
mailman.PopUsername = mailbox
mailman.PopPassword = ""
mailman.OAuth2AccessToken = token.StringOf("access_token")
success = mailman.Pop3Connect()
If (success <> True) Then
    Debug.WriteLine("Could not establish the Gmail POP3 TLS connection.")
    Exit Sub
End If

success = mailman.Pop3Authenticate()
If (success <> True) Then
    mailman.Pop3EndSessionNoQuit()
    Debug.WriteLine("POP3 authentication failed. Check the token, mailbox, POP setting, and Workspace policy.")
    Exit Sub
End If

Dim uidls As New Chilkat.StringTable
success = mailman.FetchUidls(uidls)
If (success <> True) Then
    mailman.Pop3EndSessionNoQuit()
    Debug.WriteLine("Could not list available POP UIDLs.")
    Exit Sub
End If

Dim email As New Chilkat.Email
Dim i As Integer = 0
While ((i < uidls.Count) And (i < 10))
    Dim uidl As String = uidls.StringAt(i)
    '  With headerOnly=true, zero requests headers plus the first body line.
    '  Chilkat uses TOP rather than RETR; this example does not issue DELE.
    success = mailman.FetchByUidl(uidl,True,0,email)
    If (success <> True) Then
        mailman.Pop3EndSessionNoQuit()
        Debug.WriteLine("Could not read message headers.")
        Exit Sub
    End If

    Debug.WriteLine("UIDL: " & uidl)
    Debug.WriteLine("From: " & email.From)
    Debug.WriteLine("Subject: " & email.Subject)
    i = i + 1
End While
success = mailman.Pop3EndSession()
If (success <> True) Then
    Debug.WriteLine("Headers were read, but closing the POP session failed.")
    Exit Sub
End If

Debug.WriteLine("Headers inspected: " & i)