PureBasic
PureBasic
Read Gmail POP3 Mailbox
Reads the header for each email in a GMail POP3 mailbox and displays the FROM and SUBJECT header fields. In your GMail "Forwarding and POP" settings, be sure to select "When messages are accessed with POP keep Gmail's copy in the Inbox".Chilkat PureBasic Downloads
IncludeFile "CkEmailBundle.pb"
IncludeFile "CkEmail.pb"
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; The mailman object is used for receiving (POP3)
; and sending (SMTP) email.
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Set the GMail account POP3 properties.
CkMailMan::setCkMailHost(mailman, "pop.gmail.com")
CkMailMan::setCkPopUsername(mailman, "myLogin")
CkMailMan::setCkPopPassword(mailman, "myPassword")
CkMailMan::setCkPopSsl(mailman, 1)
CkMailMan::setCkMailPort(mailman, 995)
; Read mail headers and one line of the body.
; To get the full emails, set headersOnly = 0
bundle.i = CkEmailBundle::ckCreate()
If bundle.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
keepOnServer.i = 1
headersOnly.i = 1
numBodyLines.i = 1
success = CkMailMan::ckFetchAll(mailman,keepOnServer,headersOnly,numBodyLines,bundle)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkEmailBundle::ckDispose(bundle)
ProcedureReturn
EndIf
i.i = 0
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
While i < CkEmailBundle::ckMessageCount(bundle)
CkEmailBundle::ckEmailAt(bundle,i,email)
; Display the From email address and the subject.
Debug "From: " + CkEmail::ckFrom(email)
Debug "Subject: " + CkEmail::ckSubject(email)
i = i + 1
Wend
CkMailMan::ckDispose(mailman)
CkEmailBundle::ckDispose(bundle)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure