PureBasic
PureBasic
Download the Full Version of a Partial Email
See more POP3 Examples
Demonstrates the Chilkat MailMan.FetchFull method, which downloads the complete version of a header-only or partial Email and stores it in a second Email. The full result includes the complete body and any attachments, and the partial email must retain its UIDL. This example previews message 1 (headers only) and then downloads it in full.
Background: A common pattern is to download headers first — cheap and fast — show the user a message list, and only pull the full content when a message is actually opened.
FetchFull completes that "download on demand" flow: given a partial email (which carries its UIDL), it fetches the rest from the server. This keeps bandwidth and latency low when browsing a large mailbox.Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the MailMan.FetchFull method, which downloads the complete version of a
; header-only or partial Email and stores it in a second Email. The full result includes
; the complete body and any attachments. The partial email must retain its UIDL.
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")
; First fetch message 1 as headers only (a fast preview). headerOnly=1.
partialEmail.i = CkEmail::ckCreate()
If partialEmail.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkMailMan::ckFetchOne(mailman,1,0,1,partialEmail)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkEmail::ckDispose(partialEmail)
ProcedureReturn
EndIf
Debug "Preview subject: " + CkEmail::ckSubject(partialEmail)
; Now download the complete message (body and attachments).
fullEmail.i = CkEmail::ckCreate()
If fullEmail.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkMailMan::ckFetchFull(mailman,partialEmail,fullEmail)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkEmail::ckDispose(partialEmail)
CkEmail::ckDispose(fullEmail)
ProcedureReturn
EndIf
Debug "Full email NumAttachments: " + Str(CkEmail::ckNumAttachments(fullEmail))
; 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)
CkEmail::ckDispose(partialEmail)
CkEmail::ckDispose(fullEmail)
ProcedureReturn
EndProcedure