PureBasic
PureBasic
Fetch a Single IMAP Message into an Email Object
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchEmail method, which downloads one message (or its headers) into an Email object. The arguments are headerOnly, the message id, bUid (UID vs sequence number), and the Email that receives the message. This example fetches message 1 in full and reads its subject and from.
Background:
FetchEmail parses a downloaded message into a fully navigable Email object, giving you its subject, sender, body, and attachments. Passing headerOnly = true downloads just the headers — a fast way to build a message-list preview — after which you can fetch the full message on demand. Because a mailbox must be selected first, and fetching a full message can set the \Seen flag, use ExamineMailbox instead of SelectMailbox when you must not change read state.Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Imap.FetchEmail method, which downloads one message (or its headers) into
; an Email object. The 1st argument is headerOnly, the 2nd is the message id, the 3rd
; (bUid) selects UID vs sequence number, and the 4th is the Email that receives the message.
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckLogin(imap,"user@example.com","myPassword")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckSelectMailbox(imap,"Inbox")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Download message sequence number 1 in full. headerOnly=0, bUid=0.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkImap::ckFetchEmail(imap,0,1,0,email)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "Subject: " + CkEmail::ckSubject(email)
Debug "From: " + CkEmail::ckFrom(email)
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure