Sample code for 30+ languages & platforms
PureBasic

Check the Number of Messages in a POP3 Mailbox

See more POP3 Examples

Demonstrates the Chilkat MailMan.CheckMail method, which returns the number of messages currently available in the POP3 mailbox, or -1 if an error occurs. If no POP3 session is active, Chilkat connects and authenticates automatically using the configured settings. This example configures the POP3 connection and checks the message count.

Background: POP3 (Post Office Protocol version 3) is the classic protocol for downloading mail from a server to a client. A client connects, authenticates with a username and password, and can then list, retrieve, or delete messages. Modern connections use implicit TLS on port 995 (PopSsl = true). CheckMail is a quick way to ask "how many messages are waiting?" without downloading any of them.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkMailMan.pb"

Procedure ChilkatExample()

    ;  Demonstrates the MailMan.CheckMail method, which returns the number of messages currently
    ;  available in the POP3 mailbox (or -1 if an error occurs).  If no POP3 session is active,
    ;  Chilkat connects and authenticates automatically using the configured settings.

    mailman.i = CkMailMan::ckCreate()
    If mailman.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Configure the POP3 server connection.
    CkMailMan::setCkMailHost(mailman, "pop.example.com")
    CkMailMan::setCkMailPort(mailman, 995)
    CkMailMan::setCkPopSsl(mailman, 1)
    CkMailMan::setCkPopUsername(mailman, "user@example.com")
    CkMailMan::setCkPopPassword(mailman, "myPassword")

    ;  Check the mailbox.  A return value of -1 indicates an error.
    numMessages.i = CkMailMan::ckCheckMail(mailman)
    Debug "Number of messages in the mailbox: " + Str(numMessages)

    ;  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
    ;  connects and authenticates -- using the property settings above -- whenever a server
    ;  operation requires it.  Calling the explicit connect/authenticate methods can still be
    ;  helpful to determine whether a failure occurs while connecting or while authenticating.


    CkMailMan::ckDispose(mailman)


    ProcedureReturn
EndProcedure